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


相关推荐

  • Opencv人脸识别项目简介

    Opencv人脸识别项目简介Opencv人脸识别Project综述项目要求使用opencv实现对人脸库的主成分提取(不使用PCA类),完成特征模型保存对一张测试照片进行识别,找到图片库中和测试图片最像的图配置说明Opencv3.0VS2015Win10配置过程网上太多了,就不做过多解释了,可以参照某个教程来做。主要的也就几步,下载Opencv,配Path,配置VC++目录的包含目录和库目录,配置链接器附加项的附

    2022年6月5日
    40
  • 2022pycharm 激活码(JetBrains全家桶)

    (2022pycharm 激活码)这是一篇idea技术相关文章,由全栈君为大家提供,主要知识点是关于2021JetBrains全家桶永久激活码的内容https://javaforall.net/100143.htmlIntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,上面是详细链接哦~40ZKSWCX8G-eyJsaWNlb…

    2022年4月2日
    199
  • H5移动端开发学习总结

    H5移动端开发学习总结对于移动端开发而言,为了做到页面高清的效果,视觉稿的规范往往会遵循以下两点:1.首先,选取一款手机的屏幕宽高作为基准(现在一般选取iphone6的375×667)。之前项目中也用到过iphone5的320×568。2.对于retina屏幕(如:dpr=2),为了达到高清效果,视觉稿的画布大小会是基准的2倍,也就是说像素点个数是原来的4倍(对iphone6而言:原先的375×667,就会变成

    2022年6月21日
    44
  • 什么是linux Qt[通俗易懂]

    什么是linux Qt[通俗易懂]Qt是一个跨平台的C++图形用户界面库,由挪威TrollTech公司出品,目前包括Qt,基于Framebuffer的QtEmbedded,快速开发工具QtDesigner,国际化工具QtLinguist等部分Qt支持所有Unix系统,当然也包括Linux,还支持WinNT/Win2k,Win95/98平台。

    2022年5月17日
    31
  • 安卓Menu键的问题

    安卓Menu键的问题

    2022年1月30日
    53
  • RabbitMQ(三):Exchange交换器–fanout

    RabbitMQ(三):Exchange交换器–fanout

    2021年10月5日
    38

发表回复

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

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