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;
}

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

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

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • 神经网络loss函数意义_lossfunction

    神经网络loss函数意义_lossfunctionL1Loss平均绝对误差(MAE),用于回归模型对于包含NNN个样本的batch数据D(x,y)D(x,y)D(x,y),losslossloss计算如下:loss=1N∑n=1Nlnloss=\frac{1}{N}\sum_{n=1}^{N}l_{n}loss=N1​∑n=1N​ln​其中,ln=∣xn−yn∣l_{n}=\left|x_{n}-y_{n}\right|ln​=∣xn​−yn​∣classL1Loss(_Loss):__constants__=[‘redu

  • EasySwoole的入门学习

    EasySwoole的入门学习EasySwoole的入门学习官网地址:https://www.easyswoole.com/一、安装easyswoole:(1)建立安装目录:(2)使用composer下载easyswool

  • phpStrom隐藏.idea文件[通俗易懂]

    phpStrom隐藏.idea文件[通俗易懂]phpStrom隐藏.idea文件

  • 数据结构学习——skiplist跳表

    数据结构学习——skiplist跳表目录1.skiplist简介2.skiplist核心思想3.skiplist原理3.1跳表的查找3.2跳表的插入3.3跳表的删除4.skiplist简单实现1.skiplist简介Skiplist是一个用于有序元素序列快速搜索的数据结构,由美国计算机科学家WilliamPugh发明于1989年。他在论文《Skiplists:aprobabilisticalternativetobalancedtrees》中详细介绍了跳表的数据结构和插入删除等…

    2022年10月21日
  • 配置pycharm下的tensorflow环境

    配置pycharm下的tensorflow环境PyCharm就是Python语言开发中一个很受欢迎的IDE,界面类似于visualstudio,androidstudio,集成的功能也很多。集成开发环境(IDE,IntegratedDevelopmentEnvironment)是用于提供程序开发环境的应用程序,一般包括代码编辑器、编译器、调试器和图形用户界面等工具。1.首先确保安装好了tensorflow,链接:htt…

  • 正则实现二代身份证号码验证详解[通俗易懂]

    正则实现二代身份证号码验证详解[通俗易懂]最近项目需要对身份证进行比较合理的筛选,并不想用到第三方接口,所以写了个方法:包括支持身份证号合法性验证,支持18位身份证号,支持地址编码、出生日期、校验位验证.基本上这样就可以了.IdCodeValid:function(code){ //身份证号合法性验证 //支持15位和18位身份证号 //支持地址编码、出生日期、校验位验证 varcity={11:”北京”,12:”…

发表回复

您的电子邮箱地址不会被公开。

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