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


相关推荐

  • 仓库管理(WMS)系统及其组成

    仓储管理系统(WMS)是一个实时的计算机软件系统,它能够按照运作的业务规则和运算法则,对信息、资源、行为、存货和分销运作进行更完美地管理,使其最大化满足有效产出和精确性的要求。详情连接地址:https://baike.baidu.com/item/%E4%BB%93%E5%82%A8%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F/3212656现代仓储管理系统…

    2022年4月4日
    52
  • μC/OS之OSTaskCreate()[通俗易懂]

    μC/OS之OSTaskCreate()[通俗易懂]转自 http://blog.csdn.net/xiaocaichonga/article/details/7449409建立任务OSTaskCreate()1.OSTaskCreate()函数的声明  INT8UOSTaskCreate(void(*task)(void*pd),void*pdata,OS_STK*ptos,INT8Uprio)   1.1返

    2025年9月22日
    5
  • 2019全球最火的编程语言,学哪个前景更好?(转行者必看)

    2019全球最火的编程语言,学哪个前景更好?(转行者必看)

    2022年2月11日
    41
  • Spark常见20个面试题(含大部分答案)

    Spark常见20个面试题(含大部分答案)1、什么是宽依赖,什么是窄依赖?哪些算子是宽依赖,哪些是窄依赖?窄依赖就是一个父RDD分区对应一个子RDD分区,如map,filter或者多个父RDD分区对应一个子RDD分区,如co-partionedjoin宽依赖是一个父RDD分区对应非全部的子RDD分区,如groupByKey,ruduceByKey或者一个父RDD分区对应全部的子RDD分区,如未经协同划分的joinhttps:/……

    2025年12月9日
    3
  • 安可系统对接必须java_无法运行安可开发「建议收藏」

    当我想使用纱线运行安可开发时为什么我有这个错误?当我想添加sass时,我得到警告“>sass-loader@6.0.7”有未满足的对等依赖“webpack@^2.0.0||^3.0.0||^4.0.0”.但为什么?Symfony4.我无法从github安装这个模块npminstall–savechild_processfork-ts-checker-webp…

    2022年4月6日
    64
  • 微信公众号平台开发测试怎么做_软件测试怎么测小程序

    微信公众号平台开发测试怎么做_软件测试怎么测小程序微信公众号与微信客户端之间的通信机制如下图所示:公众账号需要根据不同微信用户的不同消息做出不同的响应,所以每一个公众账号需要开发自己独有的系统,这套系统需要运行在公网环境下,但是我们通常普通开发人员没有这个条件,所以我选择了新浪云(天真的我以为是免费的,结果花了10个小洋)。第一步注册微信公众账号我用已有的微信号,扫码即可得到一个第二步注册新浪云

    2025年6月11日
    5

发表回复

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

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