HDU 5387 Clock(时分秒针之间角度)

16 篇文章 0 订阅

Clock

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


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
每行输出数据末尾均应带有空格
已知时分秒,输出时针和分针,时针和秒针 , 分针和秒针之间的角度差,,输出结果>=0 && <=180
如果不是整数 输出最简分数形式
如果x,y,z代表时分秒
那么 对于秒针
1分钟有60秒,即秒针需要走过的格数是60格,一圈是360°,因此经过1秒钟,秒针走过的角度就是360°/60秒=6°,秒针旋转的角度为 z*6
对于分针
首先跟秒针一样也是一分钟走6°,但分针走动受秒针影响的,即60秒走6°,所以 一秒钟分针走 0.1°
分针的旋转角度为 y*6 + z*0.1
对于时针一小时会走5格 即 5*6=30° ,时针会受分针和秒针的影响 ,每60分钟走30°,即一分钟时针走0.5°
每3600秒走30° 即一秒钟时针走 1/120 °
所以时针的旋转角度为 x*30 + y*0.5 * z*(1/120)
为了方便计算 通分 *120 得
秒针 : 720*z
分针: 720*y + 12*z
时针: 3600*x + 60*y + z
求出他们之间的差值 在 /120 即可
#include <cstdio>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <iostream>
#include <cmath>
#define maxn 20010
#define R 120*180
using namespace std;
int x,y,z;
int gcd(int x, int y)
{
    if (x%y) return gcd(y, x%y);
    return y;
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d:%d:%d",&x,&y,&z);
        int zz = z*6*120;
        int yy = (y*60+z)*12;
        int xx = ((x%12)*3600 + y*60 + z);    //同时扩大120倍,这样不会出现精度问题

        int xy = abs(xx - yy);    //角度差
        int xz = abs(xx - zz);
        int yz = abs(yy - zz);
        if(xy>R)                //大于180° 取小于180°的角
            xy = 2*R - xy;
        if(xz > R)
            xz = 2*R - xz;
        if(yz >R)
            yz = 2*R - yz;

        if(xy%120 == 0)         //时针和分针
            printf("%d ",xy/120);
        else
         printf("%d/%d ",xy/gcd(xy,120),120/gcd(xy,120));

        if(xz%120 == 0)          //时针和秒针
            printf("%d ",xz/120);
        else
         printf("%d/%d ",xz/ gcd(xz,120),120/ gcd(xz,120));

        if(yz%120 == 0)          //分针和秒针
            printf("%d ",yz/120);
        else
            printf("%d/%d ",yz/gcd(yz,120),120/gcd(yz,120));
        printf("\n");
    }
    return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值