Circle Through Three Points
Your team is to write a program that, given the Cartesian coordinates of three points on a plane, will find the equation of the circle through them all. The three points will not be on a straight line.
The solution is to be printed as an equation of the form
(x - h)^2 + (y - k)^2 = r^2 (1)
and an equation of the form
x^2 + y^2 + cx + dy - e = 0 (2)
Input
Each line of input to your program will contain the x and y coordinates of three points, in the order Ax, Ay, Bx, By, Cx, Cy. These coordinates will be real numbers separated from each other by one or more spaces.
Output
Your program must print the required equations on two lines using the format given in the sample below. Your computed values for h, k, r, c, d, and e in Equations 1 and 2 above are to be printed with three digits after the decimal point. Plus and minus signs in the equations should be changed as needed to avoid multiple signs before a number. Plus, minus, and equal signs must be separated from the adjacent characters by a single space on each side. No other spaces are to appear in the equations. Print a single blank line after each equation pair.
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
Southern California 1989,UVA 190
题目类型:外接圆圆心+模拟
算法分析:求出不共线三点的外接圆圆心之后直接按照题目的要求模拟即可
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
/************************************************* Author :supermaker Created Time :2016/1/30 0:03:27 File Location :C:\Users\abcd\Desktop\TheEternalPoet **************************************************/ #pragma comment(linker, "/STACK:102400000,102400000") #include <set> #include <bitset> #include <list> #include <map> #include <stack> #include <queue> #include <deque> #include <string> #include <vector> #include <ios> #include <iostream> #include <fstream> #include <sstream> #include <iomanip> #include <algorithm> #include <utility> #include <complex> #include <numeric> #include <functional> #include <cmath> #include <ctime> #include <climits> #include <cstdarg> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype> #include <cassert> using namespace std; #define CFF freopen ("aaa.txt", "r", stdin) #define CPPFF ifstream cin ("aaa.txt") #define DB(ccc) cout << #ccc << " = " << ccc << endl #define PB push_back #define MP(A, B) make_pair(A, B) typedef long long LL; typedef unsigned long long ULL; typedef double DB; typedef pair <int, int> PII; typedef pair <int, bool> PIB; const int INF = 0x7F7F7F7F; const int MOD = 1e9 + 7; const double EPS = 1e-10; const double PI = 2 * acos (0.0); const int maxn = 1e5 + 6666; int sgn (double val) { if (fabs (val) < EPS) return 0; else if (val < 0) return -1; return 1; } struct Point { double x, y; Point () {} Point (double xx, double yy) : x (xx), y (yy) {} Point operator - (const Point &a) const { return Point (x - a.x, y - a.y); } double operator ^ (const Point &a) const { return x * a.y - y * a.x; } double operator * (const Point &a) const { return x * a.x + y * a.y; } }; Point GetCircumCentre (Point a, Point b, Point c) { 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; return Point (a.x + (c1 * b2 - c2 * b1) / d, a.y + (a1 * c2 - a2 * c1) / d); } double Dist (Point p1, Point p2) { return sqrt ((p2 - p1) * (p2 - p1)); } Point p[6]; int main() { //CFF; //CPPFF; while (scanf ("%lf%lf%lf%lf%lf%lf", &p[1].x, &p[1].y, &p[2].x, &p[2].y, &p[3].x, &p[3].y) != EOF) { Point c = GetCircumCentre (p[1], p[2], p[3]); double r = Dist (c, p[1]); int is_posa = 1, is_posb = 1; if (sgn (c.x) == -1) is_posa = -1; if (sgn (c.x) == 0) is_posa = 0; if (sgn (c.y) == -1) is_posb = -1; if (sgn (c.y) == 0) is_posb = 0; if (is_posa == 1 || is_posa == 0) printf ("(x - %.3f)^2 + ", c.x); if (is_posa == -1) printf ("(x + %.3f)^2 + ", fabs (c.x)); if (is_posb == 1 || is_posb == 0) printf ("(y - %.3f)^2 = %.3f^2\n", c.y, r); if (is_posb == -1) printf ("(y + %.3f)^2 = %.3f^2\n", fabs (c.y), r); printf ("x^2 + y^2 "); double x = 2 * c.x, y = 2 * c.y; if (is_posa == 1 || is_posa == 0) printf ("- %.3fx ", fabs (x)); if (is_posa == -1) printf ("+ %.3fx ", fabs (x)); if (is_posb == 1 || is_posb == 0) printf ("- %.3fy ", fabs (y)); if (is_posb == -1) printf ("+ %.3fy ", fabs (y)); double res = c.x * c.x + c.y * c.y - r * r; if (sgn (res) >= 0) printf ("+ %.3f = 0\n", fabs (res)); else printf ("- %.3f = 0\n", fabs (res)); puts (""); } return 0; } |
- « 上一篇:poj2653
- poj1066:下一篇 »