码迷,mamicode.com
首页 > 其他好文 > 详细

HDU-5387 Clock

时间:2015-08-14 15:35:37      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:

http://acm.hdu.edu.cn/showproblem.php?pid=5387

题意:给你一个格式为hh:mm:ss的时间,问时针与分针、时针与秒针、分针与秒针之间夹角的度数是多少,若夹角度数不是整数,则输出A/B最简分数形式。 
思路:每秒钟,分针走是0.1°,时针走(1/120)°;每分钟,时针走0.5°。所以对于时针的角度来说总共走动了h*30+m*0.5+s/120,对于分针的角度来说总共走掉了m*6+s*0.1,对于秒针来说,总共走动了s*6.因为乘法比较除法来说时间复杂度更精确一点,所以我们把走的角度*120,变成全部都是整数,最后再除掉120即可。注意角度差大于180°的情况。要用360度-;

Clock

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


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技术分享 (1T10技术分享4技术分享)技术分享 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
每行输出数据末尾均应带有空格
 

 

Source
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int gcd(int x,int y)
{
    if(y%x==0)return x;
    return gcd(y%x,x);
}
int abs(int x)
{
    if(x>0)
      return x;
    else
        return -1*x;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int h,m,s,a,b,c;
        scanf("%d:%d:%d",&h,&m,&s);
        h%=12;
        h=h*3600+m*60+s;
        m=m*720+s*12;
        s=s*720;
        a=abs(h-m);
        b=abs(h-s);
        c=abs(m-s );
        if(a>120*180)
          {
              a=360*120-a;
          }
          if(b>120*180)
          {
              b=360*120-b;
          }
          if(c>120*180)
          {
              c=360*120-c;
          }
         //printf("a=%d,b=%d,c=%d\n",a,b,c);
          if(a%120==0)
             printf("%d " ,a/120);
          else
           {
               int x=gcd(a,120);
                printf("%d/%d ",a/x,120/x);
           }
           if(b%120==0)
             printf("%d " ,b/120);
          else
           {
                int y=gcd(b,120);
                printf("%d/%d ",b/y,120/y);
            }
         if(c%120==0)
             printf("%d " ,c/120);
         else
         {
           int z=gcd(c,120);
         printf("%d/%d ",c/z,120/z);
         }

        printf("\n");

    }
    return 0;
}

 

 
 

HDU-5387 Clock

标签:

原文地址:http://www.cnblogs.com/cancangood/p/4729942.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!