hdu 5705

http://acm.hdu.edu.cn/showproblem.php?pid=5705

时针每120s走1°,分针每10s走1°,所以每120s分针领先时针11°,即每120/11s,分针领先时针1°

从0:0:0开始,分针第1次与时针差a°需要a*120/11s,第2次再需要(360-2*a)*120/11s,第3次再需要a*120/11s……

所以可以从0:0:0开始走针,每次走到下一个相差a°的时间直至超过给定时间

为了避免除以11用小数带来的误差,可以在秒之下再增加一个时间单位ss,1s=11ss

#include<cstdio>

int main()
{
    int h,m,s,a,now,end,t=0,all=12*3600*11;
    bool tag;
    while(scanf("%d:%d:%d",&h,&m,&s)!=EOF)
    {
         t++;        
         scanf("%d",&a);
         end=(h*3600+m*60+s)*11;
         now=a*120;
         tag=true;
         while(now<=end)
             if(tag)
             {
                 now+=(360-2*a)*120;
                 tag^=1;
             }
             else
             {
                 now+=2*a*120;
                 tag^=1;
             }
        if(now>=all) now-=all;
        h=now/3600/11;
        now%=3600*11;
        m=now/60/11;
        now%=60*11;
        printf("Case #%d: %02d:%02d:%02d
",t,h,m,now/11);
    }
}
        
原文地址:https://www.cnblogs.com/TheRoadToTheGold/p/12212881.html