HDU 5387 Clock

Clock

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


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
每行输出数据末尾均应带有空格
 

Author
SXYZ
 

Source
 

题意:给你一个时刻,求出时针与分针,分针与秒针。秒针与时针的夹角。


题解:分别求出时针。分针。秒针与12整点的夹角,求的时候把夹角*120。再求两两的夹角除以120.


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#define ll int

using namespace std;

ll gcd(ll a,ll b) {
    return b==0?a:gcd(b,a%b);
}

int main() {
    //freopen("test.in","r",stdin);
    int t;
    cin>>t;
    while(t--) {
        int h,m,s;
        scanf("%d:%d:%d",&h,&m,&s);
        if(h>=12)h-=12;
        ///ah=h*30+0.5*m+s/120  120为分母的公倍数
        int ah=h*30*120+m*60+s;///时针与12正点的夹角*120
                               ///放大120倍是她为整数,以下同理
        int am=m*6*120+s*12;
        int as=6*s*120;
        int gd=120;
        int a1,a2,a3;
        ///时-分
        a1=ah>am?

ah-am:am-ah; a1=a1>180*120?

360*120-a1:a1; ///分-秒 a2=am>as?am-as:as-am; a2=a2>180*120?

360*120-a2:a2; ///秒-时 a3=as>ah?as-ah:ah-as; a3=a3>180*120?360*120-a3:a3; if(a1%gd==0) printf("%d ",a1/gd); else printf("%d/%d ",a1/gcd(a1,gd),gd/gcd(a1,gd)); if(a3%gd==0) printf("%d ",a3/gd); else printf("%d/%d ",a3/gcd(a3,gd),gd/gcd(a3,gd)); if(a2%gd==0) printf("%d ",a2/gd); else printf("%d/%d ",a2/gcd(a2,gd),gd/gcd(a2,gd)); cout<<endl; } return 0; }



【推广】 免费学中医,健康全家人
原文地址:https://www.cnblogs.com/llguanli/p/8624175.html