• HDU1209--Clock


    Clock
    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 3468 Accepted Submission(s): 1069


    Problem Description
    There is an analog clock with two hands: an hour hand and a minute hand. The two hands form an angle. The angle is measured as the smallest angle between the two hands. The angle between the two hands has a measure that is greater than or equal to 0 and less than or equal to 180 degrees.

    Given a sequence of five distinct times written in the format hh : mm , where hh are two digits representing full hours (00 <= hh <= 23) and mm are two digits representing minutes (00 <= mm <= 59) , you are to write a program that finds the median, that is, the third element of the sorted sequence of times in a nondecreasing order of their associated angles. Ties are broken in such a way that an earlier time precedes a later time.

    For example, suppose you are given a sequence (06:05, 07:10, 03:00, 21:00, 12:55) of times. Because the sorted sequence is (12:55, 03:00, 21:00, 06:05, 07:10), you are to report 21:00.


    Input
    The input consists of T test cases. The number of test cases (T) is given on the first line of the input file. Each test case is given on a single line, which contains a sequence of five distinct times, where times are given in the format hh : mm and are separated by a single space.


    Output
    Print exactly one line for each test case. The line is to contain the median in the format hh : mm of the times given. The following shows sample input and output for three test cases.


    Sample Input
    3
    00:00 01:00 02:00 03:00 04:00
    06:05 07:10 03:00 21:00 12:55
    11:05 12:05 13:05 14:05 15:05


    Sample Output
    02:00
    21:00
    14:05


    Source
    Asia 2003(Seoul)


    Recommend
    mcqsmall

    #include<cstdio>
    #include<cmath>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    
    struct Node
    {
        int hour,minute;
        double angle;
        int time;
    }fnode[5];
    
    bool cmp(Node a,Node b)
    {
        if(fabs(a.angle-b.angle)<1e-6)
        {
            return a.time<b.time;
        }
        return a.angle<b.angle;
    }
    
    int n;
    
    int main()
    {
        scanf("%d",&n);
        while(n--)
        {
            int i;
            for(i=0;i<5;i++)
            {
                int hour,minute;
                scanf("%d:%d",&fnode[i].hour,&fnode[i].minute);
                fnode[i].time=fnode[i].hour*60+fnode[i].minute;
                hour=fnode[i].hour,minute=fnode[i].minute;
                if(fnode[i].hour>=12)hour-=12;
                fnode[i].angle=fabs(hour*1.0/12*360-minute*1.0/60*360+minute/2.0);
                if(fnode[i].angle>=180)
                {
                    fnode[i].angle=360-fnode[i].angle;
                }
            }
            sort(fnode,fnode+5,cmp);
            if(fnode[2].hour<10)
            {
                printf("0%d:",fnode[2].hour);
            }
            else
                printf("%d:",fnode[2].hour);
            if(fnode[2].minute<10)
            {
                printf("0%d
    ",fnode[2].minute);
            }
            else
                printf("%d
    ",fnode[2].minute);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    多按键设计的标准思路
    与,非,或门总结
    i2c中应答信号信号总结
    i2c中start和restart的区别
    poj 1631 Bridging signals
    poj 2533 Longest Ordered Subsequence
    poj 1887 Testing the CATCHER
    poj 1088 滑雪
    poj 1014 Dividing
    babel转码时generator的regeneratorRuntime
  • 原文地址:https://www.cnblogs.com/zafuacm/p/3185166.html
Copyright © 2020-2023  润新知