hdu 5387 Clock
2015-08-25 17:35
302 查看
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(1≤T≤104)
test cases
for each case,one line include the time
0≤hh<24,0≤mm<60,0≤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
Sample Output
每秒钟,分针走是0.1°,时针走(1/120)°;每分钟,时针走0.5°。所以对于时针的角度来说总共走动了h*30+m*0.5+s/120,对于分针的角度来说总共走掉了m*6+s*0.1,对于秒针来说,总共走动了s*6.因为乘法比较除法来说时间复杂度更精确一点,所以我们把走的角度*120,变成全部都是整数,最后再除掉120即可。注意角度差大于180°的情况。
分数gcd形式的写法
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≤T≤104)
test cases
for each case,one line include the time
0≤hh<24,0≤mm<60,0≤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每行输出数据末尾均应带有空格
每秒钟,分针走是0.1°,时针走(1/120)°;每分钟,时针走0.5°。所以对于时针的角度来说总共走动了h*30+m*0.5+s/120,对于分针的角度来说总共走掉了m*6+s*0.1,对于秒针来说,总共走动了s*6.因为乘法比较除法来说时间复杂度更精确一点,所以我们把走的角度*120,变成全部都是整数,最后再除掉120即可。注意角度差大于180°的情况。
分数gcd形式的写法
#include <cstdio> #include <cmath> #include <iostream> #include <algorithm> using namespace std; void gcd(int a,int b) { int aa=a; int bb=b; while(b!=0) { int r=b; b=a%b; a=r; } printf("%d/%d ",aa/a,bb/a); } int main() { int t,h,m,s,a,b,c; scanf("%d",&t); while(t--) { scanf("%d:%d:%d",&h,&m,&s); h%=12; if(h==24) h=0; else if(h>12) h=h-12; h=h*3600+m*60+s; m=m*720+s*12; s*=720; a=abs(h-m); b=abs(h-s); c=abs(m-s); if(a>21600) a=43200-a; if(b>21600) b=43200-b; if(c>21600) c=43200-c; if(a%120) gcd(a,120); else printf("%d ",a/120); if(b%120) gcd(b,120); else printf("%d ",b/120); if(c%120) gcd(c,120); else printf("%d ",c/120); printf("\n"); } return 0; }
相关文章推荐
- 基于虚拟linux+docker搭建hadoop完全分布式集群
- 反射机制
- UVALive 6657
- 【写一个自己的js库】 2.实现自己的调试日志
- ElasticSearch 模板文件配置
- Unity&Socket使用TCP通信学记一
- Http断点下载实简单讲解
- 对servlet的简单理解
- 有关Java性能优化方面的策略和常见方法
- android:weightSum="2"
- test
- PHP实现 手机发送短信的程序
- Bash基础(2) 通配符 组合键 数据重定向 管道 tee
- 当内嵌图层有图层样式时,如何在其上边创建图层剪切蒙版
- Android应用开发(一):Android平台搭建与开发环境配置
- win32(二)
- android 安装 apk 遭遇 java.lang.UnsupportedOperationException: Only file:// URIs are supported
- Android应用开发(一):Android平台搭建与开发环境配置
- 打印日志
- configure: error: png.h not found.