Given a time HH:MM:SS and one parameter aa, you need to calculate next time satisfying following conditions:
1. The angle formed by the hour hand and the minute hand is aa.
2. The time may not be a integer(e.g. 12:34:56.78), rounded down(the previous example 12:34:56).
InputThe 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)(0≤HH<12,0≤MM<60,0≤SS<60).
The second line contains one integer a(0≤a≤180)a(0≤a≤180).
OutputFor 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
精度是一个问题,另一个问题是思考的角度,总是想着想着就想偏了
表盘有12个格,所以一个格的角度为360/12=30°
3600s-----1h----360/12=30°
1s-----------------(1/120)°
300s-----5min---360/12=30°
1s-----------------(1/10)°
1s时针和分针的夹角变化为11/120°
一开始可以凭借这个算一下开始的夹角,然后算出需要改变的夹角的值
那么 △角*120/11 就是需要的秒数,将这个秒数加到当前时间上去就是答案
因为可能有精度问题所以把所有的数都乘一个120
#include <bits/stdc++.h>
#define ms(a) memset(a,0,sizeof(a))
typedef long long ll;
using namespace std;
int main()
{
int hour,minute,second;
int t=0;
while(~scanf("%d:%d:%d",&hour,&minute,&second))
{
int a;
scanf("%d",&a);
int tangle = (60*minute+second)*12 - (3600*hour+60*minute+second);
tangle=(tangle+120*360)%(120*360);
int countSecond=0;
if(tangle>120*180)
{
if(360*120-tangle>120*a)
countSecond=(360*120-tangle-120*a)/11;
else
countSecond=(120*a+360*120-tangle)/11;
}
else
{
if(tangle<=120*a)
countSecond=(120*a-tangle)/11;
else
countSecond=(360*120-tangle-120*a)/11;
}
second+=countSecond,minute+=second/60,hour+=minute/60;
second%=60,minute%=60,hour%=12;
printf("Case #%d: %02d:%02d:%02d\n",++t,hour,minute,second);
}
return 0;
}