HDU 5387 Clock

Clock


Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)


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
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
每行輸出數據末尾均應帶有空格

 暴力即可,我是先求出時針、分針、秒針的角度,化簡爲分母爲120的分數,然後大角度減小角度,超過360度,減360,大於180度,用360減去原角度,通分輸出即可。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <bitset>
#include <string>
#include <vector>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main()
{
        int t;
        scanf("%d",&t);
        while(t--)
        {
                int a,b,c;
                scanf("%d:%d:%d",&a,&b,&c);
                if(a>12)
                {
                        a-=12;
                }
                int num1=(60*b+c+3600*a);
                int num2=(12*c+720*b);
                int num3=(720*c);
                int ans1;
                int ans2;
                int ans3;
                if(num1>num2)
                {
                        ans1=num1-num2;
                }
                else
                {
                        ans1=num2-num1;
                }
                //cout<<num1<<" "<<num2<<" "<<num3<<endl;
                if(num1>num3)
                {
                        ans2=num1-num3;
                }
                else
                {
                        ans2=num3-num1;
                }
                if(num2>num3)
                {
                        ans3=num2-num3;
                }
                else
                {
                        ans3=num3-num2;
                }
                if(ans1>360*120)
                {
                        ans1=-360*120+ans1;
                }
                if(ans2>360*120)
                {
                        ans2=-360*120+ans2;
                }
                if(ans3>360*120)
                {
                        ans3=-360*120+ans3;
                }
                //cout<<ans1<<" "<<ans2<<" "<<ans3<<endl;
                if(ans1>180*120)
                {
                        ans1=360*120-ans1;
                }
                if(ans2>180*120)
                {
                        ans2=360*120-ans2;
                }
                if(ans3>180*120)
                {
                        ans3=360*120-ans3;
                }
                //cout<<ans1<<" "<<ans2<<" "<<ans3<<endl;
                int gcd1=__gcd(ans1,120);
                int gcd2=__gcd(ans2,120);
                int gcd3=__gcd(ans3,120);
                if(gcd1==120)
                {
                        printf("%d ",ans1/120);
                }
                else
                {
                        printf("%d/%d ",ans1/gcd1,120/gcd1);
                }
                if(gcd2==120)
                {
                        printf("%d ",ans2/120);
                }
                else
                {
                        printf("%d/%d ",ans2/gcd2,120/gcd2);
                }
                if(gcd3==120)
                {
                        printf("%d ",ans3/120);
                }
                else
                {
                        printf("%d/%d ",ans3/gcd3,120/gcd3);
                }
                printf("\n");
        }
        return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章