http://acm.pku.edu.cn/JudgeOnline/problem?id=2957水题,但不知为何过的人很少……
其实就是通过周期算出旋转角度,把三个点移到同一个时间点上,这时问题就转化成已知三点求圆心了,贴模板水过
1 #include <cstdio>
2 #include <cmath>
3
4 struct point {
5 double x, y;
6 }p[3], c, O = {0, 0};
7
8 struct line {
9 double a, b, c;
10 };
11
12 const double EPS = 1e-8;
13 const double PI = 3.1415926535897932384626433832795;
14
15 int t, k1, k2;
16
17 point add(point p1, point p2) {
18 point v = {p1.x + p2.x, p1.y + p2.y};
19 return v;
20 }
21
22 point mul(point p, double a) {
23 point v = {p.x * a, p.y * a};
24 return v;
25 }
26
27 point rotate(point p, double th) {
28 point t = {p.x * cos(th) - p.y * sin(th), p.x * sin(th) + p.y * cos(th)};
29 return t;
30 }
31
32 int sign(double x) {
33 return x < -EPS ? -1 : x > EPS;
34 }
35
36 line getLine(point p, point v) {
37 line l = {v.y, -v.x, v.x * p.y - v.y * p.x};
38 return l;
39 }
40
41 int lineCross(line l1, line l2, point &p) {
42 double x = l1.b * l2.c - l1.c * l2.b;
43 double y = l1.a * l2.c - l1.c * l2.a;
44 double z = l1.a * l2.b - l1.b * l2.a;
45 if (!sign(z))
46 if (sign(x)) return 0;
47 else return -1;
48 else {
49 p.x = x / z; p.y = -y / z;
50 return 1;
51 }
52 }
53
54 point centre(point a, point b, point &c) {
55 point p = {b.y - a.y, a.x - b.x};
56 line l1 = getLine(mul(add(a, b), 0.5), p);
57 p.x = c.y - b.y, p.y = b.x - c.x;
58 line l2 = getLine(mul(add(b, c), 0.5), p);
59 lineCross(l1, l2, p);
60 return p;
61 }
62
63 double sqr(double x) {
64 return x * x;
65 }
66
67 double dist(point &a, point &b) {
68 return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y));
69 }
70
71 int main() {
72 while (scanf("%d%d%d", &t, &k1, &k2), t || k1 || k2) {
73 for (int i = 0; i < 3; ++i) scanf("%lf%lf", &p[i].x, &p[i].y);
74 p[0] = rotate(p[0], 2 * PI * (k1 + k2) / t);
75 p[1] = rotate(p[1], 2 * PI * k2 / t);
76 c = centre(p[0], p[1], p[2]);
77 printf("%lld\n", (long long)(dist(O, c) + 0.5));
78 }
79 return 0;
80 }
81
82