hdu 5705

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).

 

Input
The input contains multiple test cases.

Each test case contains two lines.
The first line is the time HH:MM:SS (0HH<12,0MM<60,0SS<60) .
The second line contains one integer  a(0a180) .
 

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
题意:给定一个时间作为起点,然后求下一个时针和分针的角度相差为k的时间。

思路:算出来最好了,但是我选择爆的,把下一秒的时针和分针的角度算出来,然后和题目要求的比较,然后卡精度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;
}



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值