原文連結
Problem C
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/65536K (Java/Other)
Total Submission(s) : 1 Accepted Submission(s) : 1
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
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
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
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 120
Hint
每行輸出資料末尾均應帶有空格
解釋:主要分析出秒針,分針,時針度數之間的關系,由于最後需要輸出分數形式,是以需要用到GCD
s的度數:s/60 * 360;
m的度數:m * 60 + s;
h的度數:(h%12 * 30) + (m*60 + s) / 360 * 30;
關于分數的處理,隻要把所有的分子化成3600即可;
<span style="font-size:14px;">#include <iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
using namespace std;
int gcd(int a, int b)
{
if (b > a)
{
return gcd(b, a);
}
if (b == 0)
{
return a;
}
else
{
return gcd(b, a % b);
}
}
void fun(int a, int b)
{
int c = 180 * 3600;
int max1 = max(a, b);
int min1 = min(a, b);
int res = max1 - min1;
if (res > c)
{
res = 360 * 3600 - res;
}
int tem = gcd(res, 3600);
int tem1 = 3600 / tem;
if (tem1 != 1)
{
printf("%d/%d ", res/tem, tem1);
}
else
{
printf("%d ", res/tem);
}
}
int main()
{
//freopen("E:\input.txt", "r", stdin);
int t;
scanf("%d", &t);
int h, m, s;
int ns, nm, nh;
while (t--)
{
scanf("%d:%d:%d", &h, &m, &s);
//printf("%d %d %d\n", h, m, s);
ns = s * 60 * 360;
nm = (m * 60 + s)* 360;
nh = (h % 12 * 30) * 3600 + (m * 60 + s) * 30;
fun(nh, nm);
fun(nh, ns);
fun(nm, ns);
printf("\n");
}
return 0;
}
</span>