Clock
来源:互联网 发布:php是最好的语言 编辑:程序博客网 时间:2024/05/21 15:50
Given a time HH:MM:SS and one parameter a , you need to calculate next time satisfying following conditions:
1. The angle formed by the hour hand and the minute hand isa .
2. The time may not be a integer(e.g. 12:34:56.78), rounded down(the previous example 12:34:56).
1. The angle formed by the hour hand and the minute hand is
2. The time may not be a integer(e.g. 12:34:56.78), rounded down(the previous example 12:34:56).
Each test case contains two lines.
The first line is the time HH:MM:SS
The second line contains one integer
0:59:593001:00:0030
Case #1: 01:00:00Case #2: 01:10:54
题意:给一个当前时间和一个角度,要求输出时针和分针成当前角度的一个最近时刻
首先我们推算出,秒针每走1°,分针走1/10°,时针走1/120°,所以干脆全部乘120,得到120->12->1,因此我们把120当作1°,所以只要将360*120当作秒针走一周的度数就可以处理,这样处理的优点是排除误差
接下来就可以暴力求解出几秒后可以得到解,因为我们对度数处理过,所以每过1s,时针度数+1,分针度数+12,判断一下当前锁形成的角度即可
代码如下
#include<stdio.h>#include<iostream>#include<math.h>using namespace std;int abs(int a){ if(a<0) return -a; else return a;}int main(){ int a,b,c; int g=0; while(scanf("%d:%d:%d",&a,&b,&c)!=-1) { ++g; int we; scanf("%d",&we); we=we*120; int sum=a*3600+b*60+c; int hh=sum%(360*120); int mm=(sum*12)%(360*120); int ans=0; while(1) { ans++; hh=(hh+1)%(360*120); mm=(mm+12)%(360*120); if(abs(abs(hh-mm)-we)<=10) break; } printf("Case #%d: ",g); int ansc=(ans+c)%60; int ansm=(b+(ans+c)/60)%60; int ansh=(a+((((ans+c)/60)+b)/60))%12; printf("%02d:%02d:%02d\n",ansh,ansm,ansc); }}
0 0
- clock
- clock
- clock
- Clock
- CLOCK
- clock
- Clock
- clock
- clock
- CLOCK
- clock
- Clock
- Clock
- clock
- Clock
- Clock
- clock
- clock()
- 数组指针和指针数组
- 最有可能诞生下一个BAT!这三大领域存在巨大投资机会
- shell变量关系条件测试总结
- 【ZOJ 1610】Count the Colors
- (9)caffe总结之solver优化方法
- Clock
- poj 3468 A Simple Problem with Integers(线段树——区间更新)
- uoj#34多项式乘法
- shell的数值运算方法
- bzoj2179: FFT快速傅立叶
- Rescue (BFS 优先队列)
- bzoj2194: 快速傅立叶之二
- opencv(8)---访问图像像素
- Aizu 2780 Best Matched Pair