HDU 5387 Clock

44 篇文章 0 订阅
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

简单题,直接模拟就好了

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int base=12*60*60;
const int maxn=1000005;
int a[maxn],b[maxn],c[maxn],x,y,z,T;

int gcd(int x,int y)
{
    if (x%y) return gcd(y,x%y);
    return y;
}
void put(int x,char c)
{
    if (x==0) printf("0%c",c);
    else 
    {
        x=x*360;
        int y=gcd(x,base);
        if (y!=base) printf("%d/%d%c",x/y,base/y,c);
        else printf("%d%c",x/y,c);
    }
}

void putout(int x)
{
    int m=base/2;
    int i=abs(a[x]-b[x]);
    int j=abs(a[x]-c[x]);
    int k=abs(b[x]-c[x]);
    if (i>m) i=base-i;
    if (j>m) j=base-j;
    if (k>m) k=base-k;
    put(i,' ');
    put(j,' ');
    put(k,' ');
    printf("\n");
}

int main()
{
    int tot=0;
    a[0]=b[0]=c[0]=0;
    for (int i=0;i<24;i++)
        for (int j=0;j<60;j++)
            for (int k=0;k<60;k++)
            {
                if (i+j+k==0) continue;
                tot++;
                a[tot]=(a[tot-1]+1)%base;
                b[tot]=(b[tot-1]+12)%base;
                c[tot]=(c[tot-1]+12*60)%base;
            }
    scanf("%d",&T);
    while (T--)
    {
        scanf("%d:%d:%d",&x,&y,&z);
        tot=x*60*60+y*60+z;
        putout(tot);
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值