PKU 2242 The Circumference of the Circle

http://poj.org/problem?id=2242
平面上の互いに異なる3点が与えられるとき、その三点を通る円の円周を求めろという問題。


面倒くさい思いをしました。途中でwolframAlpha使いました。

main(){
  double x1,x2,x3,y1,y2,y3;
  while(cin>>x1>>y1>>x2>>y2>>x3>>y3){
    double x=(x1*x1*(y2-y3)+x2*x2*(y3-y1)+x3*x3*(y1-y2)-(y1-y2)*(y2-y3)*(y3-y1))/
      (x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))/2;
    double y=((x1*x1+y1*y1)*(x2-x3)+(x2*x2+y2*y2)*(x3-x1)+(x3*x3+y3*y3)*(x1-x2))/
      (x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))/-2;      
    printf("%.2f\n",M_PI*2*sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1)));
  }
}