2014
03-06

# Jumping Hands

In Shanghai, there are some famous clock towers built more than 100 years ago, such as the office building of Shanghai Customs, Xujiahui Church, etc. Every clock tower’s clock-face consists of three hands: an hour hand, a minute hand, and a second hand. The hands do not move smoothly as time passing. When a second passes, the hands jump to the next place clockwise: the second hand moves 1/60 ring, the minute hand moves 1/3600 ring and the hour hand moves 1/43200 ring.

We assume that every hand’s mass is evenly distributed, and its thickness can be ignored. In other words, every hand’s centre of gravity is at the middle position of the respective hand. Suppose p1, p2 and p3 are, respectively, the position of the centre of gravity of the hour hand, that of the minute hand, and that of the second hand. The position of all three hands’ centre of gravity, P, is the average of p1, p2 and p3 weighted by the hands’ mass.

Suppose P1 and P2 are the positions of the three hands’ centre of gravity at the start time and at the end time, respectively. Your task is to calculate the length of the path from P1 to P2. That is, if P3 is the position of the three hands’ centre of gravity on the clock-face at a point of time between start time and end time, X is the length of the path from P1 to P3, and Y is the length of the path from P3 to P2, the length of the path from P1 to P2 is X+Y.

Input consists of one or more lines, each line describing one data set. Each line begins with 6 integers: L1, L2, L3, M1, M2, M3, followed by start time and end time. L1, L2 and L3 indicate the lengths of hour hand, minute hand and second hand respectively, where 1≤L1<L2<L3≤100. M1, M2 and M3 indicate the weights of hour hand, minute hand and second hand respectively, where 1≤M1, M2, M3≤100. The format of start time and end time is hh:mm:ss, where 0≤hh≤23, 0≤mm≤59, and 0≤ss≤59. Start time and end time should be in the same day.

End of input is indicated by a line consisting of -1.

Input consists of one or more lines, each line describing one data set. Each line begins with 6 integers: L1, L2, L3, M1, M2, M3, followed by start time and end time. L1, L2 and L3 indicate the lengths of hour hand, minute hand and second hand respectively, where 1≤L1<L2<L3≤100. M1, M2 and M3 indicate the weights of hour hand, minute hand and second hand respectively, where 1≤M1, M2, M3≤100. The format of start time and end time is hh:mm:ss, where 0≤hh≤23, 0≤mm≤59, and 0≤ss≤59. Start time and end time should be in the same day.

End of input is indicated by a line consisting of -1.

1 2 3 1 2 3 00:00:00 00:00:01
3 4 5 1 1 1 09:00:00 18:00:00
-1

0.08
2826.27

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

const double PI = acos(-1.0);
int l1, l2, l3, m1, m2, m3;
int hh, mm, ss;
int st, ed;

struct point_t {
double x, y;
point_t() {}
point_t(double _x, double _y) { x = _x, y = _y; }
};

double dist(const point_t &a, const point_t &b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}

point_t calc(int t) {
double a = 2.0 * PI * t / 43200.0;
double b = 2.0 * PI * t / 3600.0;
double c = 2.0 * PI * t / 60.0;
double ra = m1 * 1.0 / (m1 + m2 + m3);
double rb = m2 * 1.0 / (m1 + m2 + m3);
double rc = m3 * 1.0 / (m1 + m2 + m3);
point_t A(l1 * ra * cos(a), l1 * ra * sin(a));
point_t B(l2 * rb * cos(b), l2 * rb * sin(b));
point_t C(l3 * rc * cos(c), l3 * rc * sin(c));
return point_t(A.x + B.x + C.x, A.y + B.y + C.y);
}

int main() {
while (scanf("%d", &l1) != EOF && l1 != -1) {
scanf("%d%d%d%d%d", &l2, &l3, &m1, &m2, &m3);
scanf("%d:%d:%d", &hh, &mm, &ss);
st = hh * 3600 + mm * 60 + ss;
scanf("%d:%d:%d", &hh, &mm, &ss);
ed = hh * 3600 + mm * 60 + ss;

double ans = 0.0;
point_t pre = calc(st);
for (int t = st + 1; t <= ed; t ++) {
point_t now = calc(t);
ans += dist(pre, now);
pre = now;
}

printf("%.2lf\n", ans * 0.5);
}
return 0;
}