HDU 5705(思路题)

Clock

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 517    Accepted Submission(s): 180


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
 

Source
 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:   5775  5774  5773  5772  5771 
首先知道时针120秒走1度,分针10秒走一度。故120秒分针和时针相差11度,所以相差一度需要120/11秒,考虑到精度可以让所有的数据乘以11变成整数。时间从120秒开始枚举,直到满足条件结束, 由于前面乘以了11,结果需要除以11.
#include<cstdio>
#include<cmath>
int main(){
    int hh, mm, ss, kase = 0;
    while(scanf("%d:%d:%d", &hh, &mm, &ss) == 3){
        int a;
        scanf("%d", &a);
        int t = hh * 3600 + mm * 60 + ss;
        t *= 11;
        a *= 11;
        int i;
        int tt = 0, ttt = 0;
        for(i = 120; ; i += 120){
            tt += 11;
            if(tt > 360 * 11) ttt = tt % (11 * 360);
            else ttt = tt;
            if(ttt > 180 * 11) ttt = 360 * 11 - ttt;
            if(ttt == a && i > t) break;
        }
        i  %= 43200 * 11;
        int h = i / (3600 * 11 );
        int m = (i - h * (3600 * 11)) / (60 * 11);
        int s = (i - h * (3600 * 11) - m * (60 * 11)) / 11;
        if(h == 24) h = 0;
        printf("Case #%d: %02d:%02d:%02d\n", ++kase, h, m, s);
    }
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值