标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 3766 | Accepted: 1570 |
Description
(x - h)^2 + (y - k)^2 = r^2 (1)
x^2 + y^2 + cx + dy - e = 0 (2)
Input
Output
Sample Input
7.0 -5.0 -1.0 1.0 0.0 -6.0 1.0 7.0 8.0 6.0 7.0 -2.0
Sample Output
(x - 3.000)^2 + (y + 2.000)^2 = 5.000^2 x^2 + y^2 - 6.000x + 4.000y - 12.000 = 0 (x - 3.921)^2 + (y - 2.447)^2 = 5.409^2 x^2 + y^2 - 7.842x - 4.895y - 7.895 = 0
Source
恶心的输出..看了discuss才知道0.000要原样输出。。
#include<stdio.h> #include<iostream> #include<string.h> #include <stdlib.h> #include<math.h> #include<algorithm> using namespace std; const double pi = 3.141592653589793; const double eps = 1e-8; struct Point { double x,y; } p[3]; double dis(Point a,Point b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } ///外接圆圆心坐标 Point waixin(Point a,Point b,Point c) { Point p; double a1 = b.x - a.x, b1 = b.y - a.y, c1 = (a1*a1 + b1*b1)/2; double a2 = c.x - a.x, b2 = c.y - a.y, c2 = (a2*a2 + b2*b2)/2; double d = a1*b2 - a2*b1; p.x = a.x + (c1*b2 - c2*b1)/d, p.y=a.y + (a1*c2 -a2*c1)/d; return p; } char check(double x) { if(x<-eps) return ‘+‘; return ‘-‘; } char check2(double x) { if(x<-eps) return ‘-‘; return ‘+‘; } int main() { while(scanf("%lf%lf%lf%lf%lf%lf",&p[0].x,&p[0].y,&p[1].x,&p[1].y,&p[2].x,&p[2].y)!=EOF) { double a = dis(p[0],p[1]); double b = dis(p[1],p[2]); double c = dis(p[0],p[2]); double r = a*b*c/sqrt((a+b+c)*(-a+b+c)*(a-b+c)*(a+b-c)); Point center; center = waixin(p[0],p[1],p[2]); if(fabs(center.x)<eps) printf("x^2 + "); else printf("(x %c %.3lf)^2 + ",check(center.x),fabs(center.x)); if(fabs(center.y)<eps) printf("y^2"); else printf("(y %c %.3lf)^2",check(center.y),fabs(center.y)); printf(" = %.3lf^2\n",r); printf("x^2 + y^2"); double c1 = 2*center.x,d1=2*center.y; double r1 = center.x*center.x+center.y*center.y-r*r; printf(" %c %.3lfx %c %.3lfy %c %.3lf = 0\n\n",check(c1),fabs(c1),check(d1),fabs(d1),check2(r1),fabs(r1)); } return 0; }
标签:
原文地址:http://www.cnblogs.com/liyinggang/p/5456328.html