您的位置:首页 > 其它

hdu 5387 Clock

2015-08-25 17:35 302 查看
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每行输出数据末尾均应带有空格


每秒钟,分针走是0.1°,时针走(1/120)°;每分钟,时针走0.5°。所以对于时针的角度来说总共走动了h*30+m*0.5+s/120,对于分针的角度来说总共走掉了m*6+s*0.1,对于秒针来说,总共走动了s*6.因为乘法比较除法来说时间复杂度更精确一点,所以我们把走的角度*120,变成全部都是整数,最后再除掉120即可。注意角度差大于180°的情况。

分数gcd形式的写法

#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>

using namespace std;

void gcd(int a,int b)
{
    int aa=a;
    int bb=b;
    while(b!=0) {
        int r=b;
        b=a%b;
        a=r;
    }
    printf("%d/%d ",aa/a,bb/a);
}
int main()
{
    int t,h,m,s,a,b,c;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d:%d:%d",&h,&m,&s);
        h%=12;
        if(h==24)
          h=0;
        else if(h>12)
            h=h-12;
        h=h*3600+m*60+s;
        m=m*720+s*12;
        s*=720;
        a=abs(h-m);
        b=abs(h-s);
        c=abs(m-s);
        if(a>21600)
            a=43200-a;
        if(b>21600)
            b=43200-b;
        if(c>21600)
            c=43200-c;
        if(a%120)
            gcd(a,120);
        else
            printf("%d ",a/120);
        if(b%120)
            gcd(b,120);
        else
            printf("%d ",b/120);
        if(c%120)
            gcd(c,120);
        else
            printf("%d ",c/120);
        printf("\n");
    }
    return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: