Clock(数学题)
Clock
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 1195 Accepted Submission(s): 417
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).
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).
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
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 1195 Accepted Submission(s): 417
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).
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).
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
把时间都乘上120,进行整数之间的计算。
#include<stack> #include<queue> #include<math.h> #include<vector> #include<string> #include<stdio.h> #include<iostream> #include<string.h> #include<map> #include<algorithm> #define maxn 10000 #define MAXN 10000 #define MAXM 10005 #define mem(a,b) memset(a,b,sizeof(a)) #define ll long long #define inf 0x3f3f3f3f using namespace std; int main(){ double a,b,c;int test=0; while(~scanf("%lf:%lf:%lf",&a,&b,&c)){ int d;scanf("%d",&d); int aa=(int)a,bb=(int)b,cc=(int)c; int d1=1,d2=12,d3,d4,d5,ans,d6; int x=cc+bb*60+aa*60*60; for(int i=x+1;i<=x+46799;i++){ i%=46799; d3=(d1*i)%(360*120);d4=(d2*i)%(360*120); d5=abs(d3-d4); if(d5>(180*120))d6=(360*120-d5); if(abs(d5-d*120)<=10||abs(d6-d*120)<=10){ans=i;break;} } //cout<<ans<<endl; int ans1,ans2,ans3; ans1=ans/3600;ans1%=12; ans2=(ans%3600)/60;ans3=(ans%3600)%60; printf("Case #%d: %02d:%02d:%02d\n",++test,ans1,ans2,ans3); } }