码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 5705 Clock(模拟,分类讨论)

时间:2018-05-13 23:08:04      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:注意   second   image   ++   example   分享图片   red   content   cond   

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 , you need to calculate next time satisfying following conditions:

1. The angle formed by the hour hand and the minute hand is .
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.
The second line contains one integer .
 

 

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的时间。

【题意】
时间为12小时制。
告诉你一个时刻,让你输出在这个时刻之后的下一个时刻,
满足:该时刻,时针分针掐好相差某个的角度为a。
(注意,满足要求的时刻不一定是恰好以秒为单位,可以是秒与秒之间的时刻,我们可以向下取整)

【类型】
追及问题,判断
技术分享图片

 

 

技术分享图片

 

 

#include<stdio.h>
#include<string.h>
#include<stdio.h>  
#include<string.h>  
#include<stdlib.h>  
#include<queue>  
#include<stack>  
#include<math.h>  
#include<vector>  
#include<map>  
#include<set>  
#include<cmath>  
#include<complex>  
#include<string>  
#include<algorithm>  
#include<iostream>  
#include<string.h>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstdio>
#include<time.h>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#define inf 0x3f3f3f3f
#define ll long long
using namespace std;
int main()
{
    double h,m,s;
    char pp;
    int k=0;
    while(cin>>h>>pp>>m>>pp>>s)
    {
        k++;
        int a;
        cin>>a;
        double ah=h*30+m*0.5+s/120.0;
        while(ah>=360) ah-=360;
        double am=m*6+s/10.0;
        double x;
        if(am>=ah)
        {
            if(am-ah<=360-am+ah)
            {
                double o=am-ah;
                if(a>o) x=a-o;
                else x=360-o-a;
            }
            else
            {
                double o=360-am+ah;
                if(a>=o) x=o+a;
                else x=o-a;
            }
        }
        else
        {
            if(ah-am<=360-ah+am)
            {
                double  o=ah-am;
                if(a<o) x=o-a;
                else x=a+o;
            }
            else
            {
                double o=360-ah+am;
                if(a>o) x=a-o;
                else x=360-a-o;
            }
        }

        x=x*120/11;
        int ss=(int)(s+x);
        int y=0;
        if(ss>=60)
        {
            y=ss/60;
            ss=ss%60;
        }
        int mm=m+y;
        y=0;
        if(mm>=60)
        {
            y=mm/60;
            mm=mm%60;
        }
        int hh=h+y;
        y=0;
        if(hh>=12)
        {
            hh=hh%12;
        }
        cout<<"Case #"<<k<<": ";
        printf("%02d:%02d:%02d\n",hh,mm,ss);
    }
    return 0;
}

 

HDU 5705 Clock(模拟,分类讨论)

标签:注意   second   image   ++   example   分享图片   red   content   cond   

原文地址:https://www.cnblogs.com/caiyishuai/p/9033637.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!