HDU 5387 Clock(模拟)——(多校练习8)
来源:互联网 发布:大月氏国 知乎 编辑:程序博客网 时间:2024/05/17 21:43
Clock
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
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
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
for each case,one line include the time
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
400:00:0006:00:0012:54:5504:40:00
Sample Output
0 0 0 180 180 0 1391/24 1379/24 1/2 100 140 120Hint每行输出数据末尾均应带有空格
题意:给你一个格式为hh:mm:ss的时间,问改时间时针与分针、时针与秒针、分针与秒针之间夹角的度数是多少,若夹角度数不是整数,则输出最简分数形式A/B,即A与B互质。
解题思路:该题的思路很简单,只需先将时针、分针、秒针代表的时间转换成距离0刻度的角度,然后再求两者之间夹角的度数就会方便许多,需要注意,每秒钟,秒针对分针的贡献是0.1°,秒针对时针的贡献是(1/120)°;每分钟,分针对时针的贡献是0.5°。为了使得计算角度时均为整数,本人特地将角度放大了120倍,最后反正是要化成最简分数形式的,故再除以120即可。
其他细节之处会在代码中作出解释。
#pragma comment(linker, "/STACK:1024000000,1024000000")#include<stdio.h>#include<string.h>#include<stdlib.h>#include<queue>#include<math.h>#include<vector>#include<map>#include<set>#include<stdlib.h>#include<cmath>#include<string>#include<algorithm>#include<iostream>#define exp 1e-10using namespace std;const int N = 1005;const int inf = 1000000000;const int mod = 1000000007;void gcd(int a,int b)//利用辗转相除法求最大公约数,使得分数最简{ int m=a,n=b; while(a!=b) if(a>b) a=a-b; else b=b-a; printf("%d/%d ",m/a,n/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;//时钟一圈12小时,故24小时制的时间要转换成12小时制 h=h*3600+m*60+s;//时针、分针、秒针的角度均放大120倍,使计算过程中不会出现小数 m=m*720+s*12; s*=720; //printf("%d %d %d*\n",h,m,s); a=abs(h-m);//计算时针与分针之间的夹角 b=abs(h-s);//计算时针与秒针之间的夹角 c=abs(m-s);//计算分针与秒针之间的夹角 if(a>21600)//当夹角超过180°时,通过360°减去当前夹角使夹角小于180° a=43200-a; if(b>21600) b=43200-b; if(c>21600) c=43200-c; //printf("%d %d %d#\n",a,b,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;}
菜鸟成长记
0 0
- HDU 5387 Clock(模拟)——(多校练习8)
- HDU 5387 Clock // 模拟
- HDU 5387(2015多校8)-Clock(模拟)
- HDU 5387 Clock (MUT#8 模拟)
- HDU 5387 Clock(简单模拟)——2015 Multi-University Training Contest 8
- HDU 5387 Clock(模拟)
- HDU 5387 Clock(分数类+模拟)
- hdu 5387 Clock 2015多校联合训练赛#8
- HDU 1209 Clock(模拟)
- HDU 5705 Clock(模拟)
- 2015多校第8场 HDU 5387 Clock 模拟,计算时钟指针角度
- hdu 5387 Clock
- hdu 5387 Clock
- hdu 5387 Clock 多校
- HDU 5387 Clock
- HDU 5387 Clock
- HDU 5387 Clock
- hdu 5387 Clock
- Java并发编程的艺术——互动出版网
- 机器学习与主动学习
- 时间转换工具,显示几小时前等
- php使用ODBC连接sqlserver问题
- Spark GraphX Programming Guide 编程指南
- HDU 5387 Clock(模拟)——(多校练习8)
- Fragment进阶(四)----->参数传递3种写法
- AngularJS[ng-include]实现页面共用
- 应用内存onLowMemory& onTrimMemory优化
- hdoj 5093 Battle ships 【二分图求最大匹配】【经典建图】
- 设计模式:26 项目多也别傻做_享元模式
- android通知栏的实现
- 如何使用第三方字体
- 安卓基础