Clock
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 1020 Accepted Submission(s): 362
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这个模拟比赛的时候敲得心碎。。写了半天丢给队友。。独自郁闷。。先看看比赛的代码。#include<stdio.h> #include<string.h> #include<cmath> #include<algorithm> using namespace std; double judge(double x) { if(x<0) return x+360; if(x>360) return x-360; return x; } int main() { int h,m,s,Case = 1; double M_deg=(360.0/60)/60;///每秒分 double H_deg=M_deg*1.0/12;///时针 double Deg=M_deg-H_deg;/// int D=0; //printf("%lf\n",Deg); while(~scanf("%d:%d:%d",&h,&m,&s)) { scanf("%d",&D); double H=(s/3600.0+m/60.0+h)*(30.0); double M=(s/60.0+m)*(6.0); //printf("%f %f\n",H,M); double R,L; int res = 0; if(H>M) { //printf("$"); if(H-M>D) res = (int)((H-M-D)/Deg); else if(fabs(H-M-D) <= 1e-9) res = (int)((D*2.0)/Deg); else res = (int)((H-M+D)/Deg); } else if(fabs(M-H) <= 1e-9) { //printf("&"); res = (int)(D/Deg); } else if(H<M) { //printf("^"); if(M-H>D) { res = (int)((360.0-D-(M-H))/Deg); } else if(fabs(M-H-D) <= 1e-9) res = (int)((360.0-D-D)/Deg); else res = (int)((D-(M-H))/Deg); } //printf("**%d\n",res); while(res--) { s++; if(s==60) s=0,m++; if(m==60) m=0,h++; if(h==12) h=0; } printf("Case #%d: %02d:%02d:%02d\n",Case++,h,m,s); } }
膜一发大佬代码: 大佬链接
题意:给你一个时间和一个角度,问你下一个时针和分针形成给出的角度是什么时候
题解:我们可以将这个问题看成追及问题,考虑时针:每小时30°,每分钟1/2°,每秒1/120°,考虑分针:没分钟6°,每秒1/10°,如果我把全部同时乘一个120,不就能避免精度造成的问题了吗!现在再来考虑时针和分针的位置情况:这里我们以分针按顺时针的方向到时针
1:当时针和分针的θ∠大于180*120时(1)当(360*120-θ)大于给出的角度an时,需要的时间ans=h+(θ-an*120)/11,/11是因为每秒钟时针走1°,分针走12°。(2)当(360*120-θ)小于给出的角度an时,需要的时间ans=h+(θ-(360-an)*120)/11
2:当时针和分针的θ∠小于180*120时(1)当(360*120-θ)大于给出的角度an时,需要的时间ans=h+(θ-an*120)/11。(2)当(360*120-θ)小于给出的角度an时,需要的时间ans=h+(θ+an*120)/11。
最后再根据经过的时间算出当前的时间