ZOJ 2680 Clock()数学

ZOJ 2680 Clock()数学

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

主题链接: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 (South Korea)

题意:

//给出 5 个时刻,按时钟的时针,分针夹角从小到大排序,
//输出中间的时刻。

代码例如以下:

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
struct TIME
{
    int h;
    int m;
    int angle;
}a[7];

int cal(TIME TT)
{
    if(TT.h > 12)
    {
        TT.h-=12;
    }
    int tt = abs((TT.h*60 + TT.m) - TT.m*12);
    //原式为:TT.h*30+(TT.m/60)*30-a.m*6;
    if(tt > 360)
        tt = 720 - tt;
    return tt;
}
bool cmp(TIME A, TIME B)
{
    if(A.angle != B.angle)
    {
        return A.angle < B.angle;
    }
    else if(A.h != B.h)
    {
        return A.h < B.h;
    }
    else
        return A.m < B.m;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        for(int i = 0; i < 5; i++)
        {
            scanf("%d:%d",&a[i].h,&a[i].m);
            a[i].angle = cal(a[i]);
        }
        sort(a,a+5,cmp);
        printf("%02d:%02d\n",a[2].h,a[2].m);
    }
    return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/116756.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长

相关推荐

  • 创建和调用动态链接库方法

    创建和调用动态链接库方法

    2021年9月3日
  • stimulsoft oracle,报表仪表设计器Stimulsoft的处理数据功能

    stimulsoft oracle,报表仪表设计器Stimulsoft的处理数据功能StimulsoftReports.Net是一个基于.NET框架的报表生成器,能够帮助你创建结构、功能丰富的报表。StimulReport.Net的报表设计器不仅界面友好,而且使用便捷,能够让你轻松创建所有报表;该报表设计器在报表设计过程中以及报表运行的过程中都可以使用。在运行时使用StimulReport.Net的报表设计器不需要支付任何的专利费用。所创建的报表既可以在Windows窗体应用…

    2022年7月13日
  • chmod修改权限的用法

    一、chmod作用:修改文件、目录的权限二、语法:chmod[对谁操作][操作符][赋予的权限]文件名三、操作对象:u用户user,表现文件或目录的所有者g用户组group,表现文件或目录所属的用户组o其他用户other…

    2022年4月5日
  • psp坏点修复(psp贴吧)

    psp坏点&鉴别液晶坏点  暗点 亮点PC上挑选液晶LCD,借助第3方软件 例如NOKIA MONITOR TESTER 需要指出的是,亮点,暗点,坏点问题是液晶屏幕不可避免的先天性"生理缺陷",一般情况下,3个以下的"点"都是可以接受的.亮点:在黑屏幕情况下单纯地显示一种颜色的点,通常表现为在RED,GREEN,BLUE3种纯色模式下均显示白色.暗点:在R G B3种纯色模式下,均显示为黑色或不

    2022年4月15日
  • Smartphone 2.0 = Phone + Service

    Smartphone 2.0 = Phone + Service

    2021年7月30日
  • webpack(6)webpack处理图片

    webpack(6)webpack处理图片图片处理url-loader(webpack5之前的处理方式)在项目开发中,我们时长会需要使用到图片,比如在img文件夹中有图片test1.png,然后在normal.css中会引用到图片body

    2022年7月29日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号