POJ 1329
模板题,注意一下输出就可以。
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> using namespace std; struct point { double x,y; }; struct triangle{ point t[3]; }t; struct Circle{ double x,y; double r; }tmp; double dist(point p1, point p2){ return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)); } double triangleArea(){ return fabs(t.t[0].x*t.t[1].y+t.t[1].x*t.t[2].y+t.t[2].x*t.t[0].y- t.t[1].x*t.t[0].y-t.t[2].x*t.t[1].y-t.t[0].x*t.t[2].y)/2; } int main(){ double x1,y1,x2,y2,x3,y3; while(scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3)!=EOF){ t.t[0].x=x1; t.t[0].y=y1; t.t[1].x=x2; t.t[1].y=y2; t.t[2].x=x3; t.t[2].y=y3; double a,b,c; a=dist(t.t[0],t.t[1]); b=dist(t.t[1],t.t[2]); c=dist(t.t[2],t.t[0]); tmp.r=(a*b*c)/triangleArea()/4; double c1=(x1*x1+y1*y1-x2*x2-y2*y2)/2; double c2=(x1*x1+y1*y1-x3*x3-y3*y3)/2; tmp.x=(c1*(y1-y3)-c2*(y1-y2))/((x1-x2)*(y1-y3)-(x1-x3)*(y1-y2)); tmp.y=(c1*(x1-x3)-c2*(x1-x2))/((y1-y2)*(x1-x3)-(y1-y3)*(x1-x2)); printf("(x"); if(tmp.x>=0) printf(" - %0.3lf)^2 + (y",tmp.x); else printf(" + %0.3lf)^2 + (y",-tmp.x); if(tmp.y>=0) printf(" - %0.3lf)^2 =",tmp.y); else printf(" + %0.3lf)^2 =",-tmp.y); printf(" %0.3lf^2\n",tmp.r); printf("x^2 + y^2"); if(tmp.x>0) printf(" - %0.3lfx",2*tmp.x); else printf(" + %0.3lfx",-2*tmp.x); if(tmp.y>0) printf(" - %0.3lfy",2*tmp.y); else printf(" + %0.3lfy",-2*tmp.y); double ans=tmp.x*tmp.x+tmp.y*tmp.y-tmp.r*tmp.r; if(ans<0){ printf(" - %.3lf = 0\n",-ans); } else printf(" + %.3lf = 0\n",ans); printf("\n"); } return 0; }