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

Posted 蔡军帅

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU 5705 Clock(模拟,分类讨论)相关的知识,希望对你有一定的参考价值。

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(模拟,分类讨论)的主要内容,如果未能解决你的问题,请参考以下文章

HDU 5705 Clock(2016杭电女生专场1004)——角度追及问题

hdu5387(2015多校8)--Clock(模拟)

HDU 5387 Clock(分数类+模拟)

HDU-5705

二分三角形的时候尤其需要注意!!! HDU 5115 二分+模拟

HDU 5387Clock