Clock
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 517 Accepted Submission(s): 180
Problem Description
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 is a .
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 a .
2. The time may not be a integer(e.g. 12:34:56.78), rounded down(the previous example 12:34:56).
Input
The input contains multiple test cases.
Each test case contains two lines.
The first line is the time HH:MM:SS (0≤HH<12,0≤MM<60,0≤SS<60) .
The second line contains one integer a(0≤a≤180) .
Each test case contains two lines.
The first line is the time HH:MM:SS (0≤HH<12,0≤MM<60,0≤SS<60) .
The second line contains one integer a(0≤a≤180) .
Output
For each test case, output a single line contains test case number and the answer HH:MM:SS.
Sample Input
0:59:59 30 01:00:00 30
Sample Output
Case #1: 01:00:00 Case #2: 01:10:54
Source
Recommend
首先知道时针120秒走1度,分针10秒走一度。故120秒分针和时针相差11度,所以相差一度需要120/11秒,考虑到精度可以让所有的数据乘以11变成整数。时间从120秒开始枚举,直到满足条件结束, 由于前面乘以了11,结果需要除以11.
#include<cstdio>
#include<cmath>
int main(){
int hh, mm, ss, kase = 0;
while(scanf("%d:%d:%d", &hh, &mm, &ss) == 3){
int a;
scanf("%d", &a);
int t = hh * 3600 + mm * 60 + ss;
t *= 11;
a *= 11;
int i;
int tt = 0, ttt = 0;
for(i = 120; ; i += 120){
tt += 11;
if(tt > 360 * 11) ttt = tt % (11 * 360);
else ttt = tt;
if(ttt > 180 * 11) ttt = 360 * 11 - ttt;
if(ttt == a && i > t) break;
}
i %= 43200 * 11;
int h = i / (3600 * 11 );
int m = (i - h * (3600 * 11)) / (60 * 11);
int s = (i - h * (3600 * 11) - m * (60 * 11)) / 11;
if(h == 24) h = 0;
printf("Case #%d: %02d:%02d:%02d\n", ++kase, h, m, s);
}
}