HDU5387 Clock 时钟模拟
来源:互联网 发布:ug软件自学网 编辑:程序博客网 时间:2024/05/16 02:05
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5387
题目大意:给出一个24小时制的时间,分别找出时针-分针,时针-秒针,分针-秒针之间的角度。
分析:在纸上算一下就行了。对于这三个角度,我们可以选12时作为参考点,然后分别找出时针,分针,秒针和参考点之间的角度,然后用这个角度相减就得到了两根指针之间的相对角度了。
实现代码如下:
#include <iostream>#include <cstdio>#include <cmath>using namespace std;int gcd(int a,int b){ return b?gcd(b,a%b):a;}int main(){ int t; cin>>t; int h,m,s; while(t--) { scanf("%d:%d:%d",&h,&m,&s); h=h%12; int hm=fabs(3600*h-660*m-11*s),hm1=120; if(hm>21600) hm=43200-hm; int hs=fabs(3600*h+60*m-719*s),hs1=120; if(hs>21600) hs=43200-hs; int ms=fabs(60*m-59*s),ms1=10; if(ms>1800) ms=3600-ms; //printf("%d %d %d\n",hm,hs,ms); int a1=gcd(hm,hm1); int a2=gcd(hs,hs1); int a3=gcd(ms,ms1); if(a1>1) { hm/=a1; hm1/=a1; } if(a2>1) { hs/=a2; hs1/=a2; } if(a3>1) { ms/=a3; ms1/=a3; } if(hm1==1) printf("%d ",hm); else printf("%d/%d ",hm,hm1); if(hs1==1) printf("%d ",hs); else printf("%d/%d ",hs,hs1); if(ms1==1) printf("%d \n",ms); else printf("%d/%d \n",ms,ms1); } return 0;}
0 0
- HDU5387 Clock 时钟模拟
- hdu5387 模拟时钟
- hdu5387 六校 Clock(水题 模拟)
- hdu5387(2015多校8)--Clock(模拟)
- hdu5387 Clock
- hdu5387 Clock
- hdu5387 Clock(分数加减法模拟及分数化简)
- hdu5387(模拟)
- hdu5387 Clock(数学水题)
- HDU5387
- 实训C++语言设计——Clock模拟时钟系统
- 开源项目之 Wall Clock Control(模拟时钟)
- [水题] hdu5387 多校联合第八场 Clock
- Clock Domains--时钟域
- s5pv210------clock时钟管理
- 时钟——clock
- SharePoint Silverlight Clock 时钟
- java时钟面板clock
- Rank List
- android oom
- leetcode-39/40 Combination Sum / II
- Hololens开发,Unity不是必选的,但当下是唯一的
- HDU1823-二维线段树
- HDU5387 Clock 时钟模拟
- 【java】注解
- Ehcache 整合Spring 使用页面、对象缓存
- Chapter 11 – Running the simulation
- Cocos2d-x学习笔记(九)—— 地图系统(地图编辑器,事件响应)
- 伸展树
- [android]Android Studio使用Genymotion安卓模拟器
- hdu5384(AC自动机)
- nginx的root和alias指令的区别