Clock
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 189 Accepted Submission(s): 135
Problem Description
Give a time.(hh:mm:ss),you should answer the angle between any two of the minute.hour.second hand
Notice that the answer must be not more 180 and not less than 0
Notice that the answer must be not more 180 and not less than 0
Input
There are
T
(1≤T≤104)
test cases
for each case,one line include the time
0≤hh<24 , 0≤mm<60 , 0≤ss<60
for each case,one line include the time
0≤hh<24 , 0≤mm<60 , 0≤ss<60
Output
for each case,output there real number like A/B.(A and B are coprime).if it's an integer then just print it.describe the angle between hour and minute,hour and second hand,minute and second hand.
Sample Input
4 00:00:00 06:00:00 12:54:55 04:40:00
Sample Output
0 0 0 180 180 0 1391/24 1379/24 1/2 100 140 120Hint每行输出数据末尾均应带有空格已知时分秒,输出时针和分针,时针和秒针 , 分针和秒针之间的角度差,,输出结果>=0 && <=180如果不是整数 输出最简分数形式如果x,y,z代表时分秒那么 对于秒针1分钟有60秒,即秒针需要走过的格数是60格,一圈是360°,因此经过1秒钟,秒针走过的角度就是360°/60秒=6°,秒针旋转的角度为 z*6对于分针首先跟秒针一样也是一分钟走6°,但分针走动受秒针影响的,即60秒走6°,所以 一秒钟分针走 0.1°分针的旋转角度为 y*6 + z*0.1对于时针一小时会走5格 即 5*6=30° ,时针会受分针和秒针的影响 ,每60分钟走30°,即一分钟时针走0.5°每3600秒走30° 即一秒钟时针走 1/120 °所以时针的旋转角度为 x*30 + y*0.5 * z*(1/120)为了方便计算 通分 *120 得秒针 : 720*z分针: 720*y + 12*z时针: 3600*x + 60*y + z求出他们之间的差值 在 /120 即可#include <cstdio> #include <algorithm> #include <stdlib.h> #include <cstring> #include <iostream> #include <cmath> #define maxn 20010 #define R 120*180 using namespace std; int x,y,z; int gcd(int x, int y) { if (x%y) return gcd(y, x%y); return y; } int main() { int T; scanf("%d",&T); while(T--) { scanf("%d:%d:%d",&x,&y,&z); int zz = z*6*120; int yy = (y*60+z)*12; int xx = ((x%12)*3600 + y*60 + z); //同时扩大120倍,这样不会出现精度问题 int xy = abs(xx - yy); //角度差 int xz = abs(xx - zz); int yz = abs(yy - zz); if(xy>R) //大于180° 取小于180°的角 xy = 2*R - xy; if(xz > R) xz = 2*R - xz; if(yz >R) yz = 2*R - yz; if(xy%120 == 0) //时针和分针 printf("%d ",xy/120); else printf("%d/%d ",xy/gcd(xy,120),120/gcd(xy,120)); if(xz%120 == 0) //时针和秒针 printf("%d ",xz/120); else printf("%d/%d ",xz/ gcd(xz,120),120/ gcd(xz,120)); if(yz%120 == 0) //分针和秒针 printf("%d ",yz/120); else printf("%d/%d ",yz/gcd(yz,120),120/gcd(yz,120)); printf("\n"); } return 0; }