Clock
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 500 Accepted Submission(s): 176
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
思路:算出来最好了,但是我选择爆的,把下一秒的时针和分针的角度算出来,然后和题目要求的比较,然后卡精度0.09过了,一开始0.05是卡样例,没过,0.1样例都不过,然后0.09就过了,神奇的精度。
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
int m,h,s,kase = 1;
int fh,fm,fs;
double fin;
while(scanf("%d:%d:%d",&h,&m,&s)!=EOF)
{
int anl;
scanf("%d",&anl);
for(int i = 1;i <= 43200;i++)
{
s++;
if(s>=60)
{
s%=60;
m++;
}
if(m>=60)
{
m-=60;
h++;
}
if(h>=12)
{
h-=12;
}
double anlm = m*6.0+s/10.0;
double anlh = h*30+anlm/12.0;
double dif1 = anlh-anl;
if(dif1<=-1e-6)
dif1+=360.0;
double dif2 = anlh+anl;
if(dif2>=360+1e-6)
dif2-=360.0;
//printf("%d %d %d:%lf %lf %lf\n",h,m,s,anlm,dif1,dif2);
if(fabs(anlm - dif1)<=0.09||fabs(anlm - dif2)<=0.09)
{
printf("Case #%d: ",kase++);
printf("%.2d:%.2d:%.2d\n",h,m,s);
break;
}
}
}
return 0;
}