[水题] hdu5387 多校联合第八场 Clock

来源:互联网 发布:图片做成视频软件 编辑:程序博客网 时间:2024/06/04 17:59

Clock

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1320    Accepted Submission(s): 601


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(1T104) test cases
for each case,one line include the time

0hh<24,0mm<60,0ss<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
400:00:0006:00:0012:54:5504:40:00
 

Sample Output
0 0 0 180 180 0 1391/24 1379/24 1/2 100 140 120
Hint
每行输出数据末尾均应带有空格


没别的,模拟一下就好了。。计算的时候注意取两边的夹角有可能是大于180度的角,这时候要算另外一边比较小的角。

#include <cstdio>#include <cstring>#include<cmath>#include<algorithm>using namespace std;int gcd(int a,int b){    if (b==0)return a;    return gcd(b,a%b);}int main(){    int n;    int hh,mm,ss;    //freopen("in.txt","r",stdin);    scanf("%d",&n);    while(n--)    {        scanf("%d:%d:%d",&hh,&mm,&ss);        //一圈总共有43200秒;        int hour = 3600*hh + 60*mm + ss;        int minute = 720*mm + 12*ss;        int sec = 720*ss;        while(hour >= 43200) hour -= 43200;        while(minute >= 43200) minute -= 43200;        while(sec >= 43200) sec -= 43200;        int a1 = min(abs(hour - minute),43200-abs(hour-minute));        int a2 = min(abs(hour - sec),43200-abs(hour-sec));        int a3 = min(abs(minute -sec),43200-abs(minute - sec));        int b1,b2,b3;        b1 = 120 / gcd(a1,120);        b2 = 120 / gcd(a2,120);        b3 = 120 / gcd(a3,120);        b1 == 1 ?  printf("%d ",a1/120):printf("%d/%d ",a1/gcd(a1,120),b1);        b2 == 1 ?  printf("%d ",a2/120):printf("%d/%d ",a2/gcd(a2,120),b2);        b3 == 1 ?  printf("%d ",a3/120):printf("%d/%d ",a3/gcd(a3,120),b3);        printf("\n");    }    return 0;}




0 0
原创粉丝点击