前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【HDU 5387】Clock

【HDU 5387】Clock

作者头像
饶文津
发布2020-06-02 11:37:48
4480
发布2020-06-02 11:37:48
举报
文章被收录于专栏:饶文津的专栏

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$$(1\leq T \leq 10^4)$ test cases  for each case,one line include the time  $0\leq hh<24$,$0\leq mm<60$,$0\leq ss<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

代码语言:javascript
复制
每行输出数据末尾均应带有空格 

题意:

求给定时间点的时针、分针、秒针的夹角(分数、角度制)

分析:

tol=总秒数,时针1/120 °/s,分针1/10 °/s,秒针 6 °/s,

分针和时针转过的角度差(tol/10-tol/120)=11*tol/120;

秒针和时针转过的角度差(6*tol-tol/120)=719*tol/120;

秒针和分针转过的角度差(6*tol-tol/10)=59*tol/10;

然后前两个角度差的分子%(120*360)即%43200,后面一个%3600,这样就<360了,就是我们要求的夹角或其补角了。

然后判断夹角up/down 是否大于180度,刚开始我让它>180就360减去它,但是 这里是整除,也就是180多一点点的整除了变成180,所以要写成>=180或>179时就让360减去它。

接下来约分输出。

代码:

代码语言:javascript
复制
 1 #include<stdio.h>
 2 int t,h,m,s,tol,up[4],down[4],g;
 3 int gcd(int a,int b)
 4 {return b?gcd(b,a%b):a;}
 5 int main()
 6 {
 7     scanf("%d",&t);
 8     while(t--)
 9     {
10         scanf("%d:%d:%d",&h,&m,&s);
11         tol=h*3600+m*60+s;
12         up[0]=(11*tol)%(43200);
13         up[1]=(719*tol)%(43200);
14         up[2]=(59*tol)%(3600);
15         down[0]=down[1]=120;down[2]=10;
16         for(int i=0; i<3; i++)
17         {
18             g=gcd(up[i],down[i]);
19             up[i]/=g;down[i]/=g;
20             if(up[i]/down[i]>179)up[i]=down[i]*360-up[i];
21             if(down[i]==1)printf("%d ",up[i]);
22             else printf("%d/%d ",up[i],down[i]);
23         }
24         printf("\n");
25     }
26     return 0;
27 }
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016-02-06 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Description
  • Input
  • Output
  • Sample Input
  • Sample Output
  • Hint
  • 题意:
  • 分析:
  • 代码:
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档