题目大意:
对时钟的时间hh:mm:ss定义一个平面中的点, 它由时针, 分针, 秒针的质量, 长度, 位置决定, 三根指针分别有长度和质量, 质量均匀分布, 则该时钟的这个时间对应三根指针质心的重心. 给一个初始时间和结束时间, 计算这个点的路程.
简要分析:
模拟题, 每一秒算一下那个奇葩的点就行了啊. 时间复杂度O(T).
代码实现:
1 #include <cmath>
2 #include <cstdio>
3 #include <cstdlib>
4 #include <cstring>
5 #include <algorithm>
6 using namespace std;
7
8 const double PI = acos(-1.0);
9 int l1, l2, l3, m1, m2, m3;
10 int hh, mm, ss;
11 int st, ed;
12
13 struct point_t {
14 double x, y;
15 point_t() {}
16 point_t(double _x, double _y) { x = _x, y = _y; }
17 };
18
19 double dist(const point_t &a, const point_t &b) {
20 return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
21 }
22
23 point_t calc(int t) {
24 double a = 2.0 * PI * t / 43200.0;
25 double b = 2.0 * PI * t / 3600.0;
26 double c = 2.0 * PI * t / 60.0;
27 double ra = m1 * 1.0 / (m1 + m2 + m3);
28 double rb = m2 * 1.0 / (m1 + m2 + m3);
29 double rc = m3 * 1.0 / (m1 + m2 + m3);
30 point_t A(l1 * ra * cos(a), l1 * ra * sin(a));
31 point_t B(l2 * rb * cos(b), l2 * rb * sin(b));
32 point_t C(l3 * rc * cos(c), l3 * rc * sin(c));
33 return point_t(A.x + B.x + C.x, A.y + B.y + C.y);
34 }
35
36 int main() {
37 while (scanf("%d", &l1) != EOF && l1 != -1) {
38 scanf("%d%d%d%d%d", &l2, &l3, &m1, &m2, &m3);
39 scanf("%d:%d:%d", &hh, &mm, &ss);
40 st = hh * 3600 + mm * 60 + ss;
41 scanf("%d:%d:%d", &hh, &mm, &ss);
42 ed = hh * 3600 + mm * 60 + ss;
43
44 double ans = 0.0;
45 point_t pre = calc(st);
46 for (int t = st + 1; t <= ed; t ++) {
47 point_t now = calc(t);
48 ans += dist(pre, now);
49 pre = now;
50 }
51
52 printf("%.2lf\n", ans * 0.5);
53 }
54 return 0;
55 }