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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Java中将xml文件转化为json的两种方式

    Java中将xml文件转化为json的两种方式最近一直没有时间写博客,忙着找房子,天天来回折腾,光地铁费就花了不少,最后综合各种因素考虑,决定沙河高教园,哈哈,没错,别人都是越搬离公司越近,我是越搬越远,但是直觉告诉我应该没有错,昨天晚上刚搬完家,收拾收拾终于安定了,坑爹的二房东再见,以后如果不出什么特殊情况的话应该是有时间写博客了。。。。    好了废话不多说,进入正题,最近有个需求,要将xml转json之后存储在redi

    2022年7月21日
    11
  • PHP json_decode[通俗易懂]

    PHP json_decode[通俗易懂]json_decode(PHP5>=5.2.0,PECLjson>=1.2.0)json_decode — 对JSON格式的字符串进行编码说明 ¶mixed json_decode ( string $json [, bool $assoc =false [, int $depth =512 [, int $options =0 

    2022年7月12日
    18
  • Oracle中的NULL、’’(空字符串)以及’_’(空格)

    Oracle中的NULL、’’(空字符串)以及’_’(空格)

    2021年9月12日
    135
  • XOR问题

    XOR问题在Rosenblatt单层感知机中已经对异或问题做了介绍,并论证说明了只适用于线性分类问题的Rosenblatt感知机无法对异或问题进行分类。然而非线性问题是普遍存在的,下面就使用带隐藏节点的神经网络来解决异或问题。异或问题:异或(XOR)问题可以看做是单位正方形的四个角,响应的输入模式为(0,0),(0,1),(1,1),(1,0)。第一个和第三个模式属于类0,即和…

    2022年7月16日
    26
  • Python如何将py文件打包成exe[通俗易懂]

    Python如何将py文件打包成exe[通俗易懂]安装pyinstaller打开cmd窗口,输入pipinstallpyinstaller,命令行输出successfully表示成功。生成exe文件一、单个py文件在py文件目录下,打开c

    2022年7月6日
    35
  • pycharm中debug无法调试_pycharm配置debug

    pycharm中debug无法调试_pycharm配置debug在多次跑项目中遇到情况,pacharm突然就无法运行项目了,表现就是run和debug两个选项按钮全部变灰色无法点击。造成这种情况的原因是因为我在一个很大的文件下创建了新的文件,每次运行都要为所有文件建造索引,文件很大的话这个时间就比较长,表现就是右下角有个进度条一直在刷新。这个时候的做法就是:右键文件名——&gt; Markdirectoryas… ——&gt;Exclude…

    2022年8月29日
    3

发表回复

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

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