标签:cto 输出 order find sep type should contain point
题目链接:
http://poj.org/problem?id=1329
题目描述:
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
题目大意:
给三个点求出三角形外接圆
并输出圆的标准型和一般型
思路:
套模板
注意输出处理数值为0(输出x^2)
代码:
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <cmath> 6 #include <vector> 7 using namespace std; 8 9 const double EPS = 1e-10; //精度系数 10 const double PI = acos(-1.0); //π 11 12 13 struct Point { 14 double x, y; 15 Point(double x = 0, double y = 0) :x(x), y(y) {} 16 }; //点的定义 17 18 typedef Point Vector; //向量的定义 19 20 Vector operator - (Vector A, Vector B) { return Vector(A.x - B.x, A.y - B.y); } //向量减法 21 22 int dcmp(double x) { 23 if (fabs(x) < EPS)return 0; else return x < 0 ? -1 : 1; 24 } //与0的关系 25 26 double Dot(Vector A, Vector B) { return A.x*B.x + A.y*B.y; } //向量点乘 27 double Length(Vector A) { return sqrt(Dot(A, A)); } //向量长度 28 29 struct Circle { 30 Point c; 31 double r; 32 Circle() :c(Point(0, 0)), r(0) {} 33 Circle(Point c, double r = 0) :c(c), r(r) {} 34 Point point(double a) { return Point(c.x + cos(a)*r, c.y + sin(a)*r); } //输入极角返回点坐标 35 }; //圆 36 37 Circle CircumscribedCircle(Point p1, Point p2, Point p3) { 38 double Bx = p2.x - p1.x, By = p2.y - p1.y; 39 double Cx = p3.x - p1.x, Cy = p3.y - p1.y; 40 double D = 2 * (Bx*Cy - By*Cx); 41 double cx = (Cy*(Bx*Bx + By*By) - By*(Cx*Cx + Cy*Cy)) / D + p1.x; 42 double cy = (Bx*(Cx*Cx + Cy*Cy) - Cx*(Bx*Bx + By*By)) / D + p1.y; 43 Point p = Point(cx, cy); 44 return Circle(p, Length(p1 - p)); 45 } //三角形外接圆 46 47 Point A, B, C; 48 49 void print(double num) { 50 if (dcmp(num) < 0) { printf("- "); num = -num; } else printf("+ "); 51 printf("%.3lf", num); 52 } //输出 53 54 int main() { 55 while (~scanf("%lf%lf%lf%lf%lf%lf", &A.x, &A.y, &B.x, &B.y, &C.x, &C.y)) { 56 Circle ans = CircumscribedCircle(A, B, C); 57 double a = ans.c.x, b = ans.c.y; 58 double c = -2 * a, d = -2 * b, e = a*a + b*b - ans.r*ans.r; 59 int tmp = dcmp(a); 60 if (tmp == 0)printf("x^2"); 61 else { printf("(x "); print(-a); printf(")^2"); } 62 printf(" + "); 63 tmp = dcmp(b); 64 if (tmp == 0)printf("y^2"); 65 else { printf("(y "); print(-b); printf(")^2"); } 66 printf(" = %.3lf^2\n", ans.r); 67 printf("x^2 + y^2 "); print(c); printf("x "); print(d); printf("y "); print(e); 68 printf(" = 0\n\n"); 69 } 70 }
POJ1329 Circle Through Three Points(三角形外接圆)
标签:cto 输出 order find sep type should contain point
原文地址:http://www.cnblogs.com/hyp1231/p/7092156.html