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


相关推荐

  • 操作系统实验一进程管理实验报告_对进程的管理和控制使用

    操作系统实验一进程管理实验报告_对进程的管理和控制使用实验一进程管理1.目的和要求通过实验理解进程的概念,进程的组成(PCB结构),进程的并发执行和操作系统进行进程管理的相关原语(主要是进程的创建、执行、撤消)。2.实验内容用C语言编程模拟进程管理,至少要有:创建新的进程;查看运行进程;换出某个进程;杀死运行进程以及进程之间通信等功能。3.实验环境Windows操作系统、VC++6.0C语言4.实验提示PCB结…

    2025年10月20日
    3
  • 在配置maven的阿里镜像遇到的问题

    在配置maven的阿里镜像遇到的问题

    2021年7月11日
    108
  • 列举出linux文件和目录常用的命令_查看centos根目录下有哪些内容

    列举出linux文件和目录常用的命令_查看centos根目录下有哪些内容目录命令总览ls(英文全拼:listfiles):列出目录及文件名cd(英文全拼:changedirectory):切换目录pwd(英文全拼:printworkdirectory):显

    2022年7月29日
    5
  • NVIC中断管理

    NVIC中断管理使用中断之前,第一步要了解的是其优先级管理,下面总结一下STM32NVIC的中断优先级管理。(正点原子系列)以smt32f103系列为例,其具有16个内核中断和60个可屏蔽中断。下面介绍其库函数的开发:MDK内与NVIC相关的寄存器包含在结构体中,通过创建结构体,配置其内部组成员也就是寄存器,来配置NVIC各个配置。先介绍其结构体的内部内容:在结构体内有介绍!中断配置寄存器[]内的…

    2022年5月27日
    71
  • 资源小屋-小屋论坛 开通[通俗易懂]

    资源小屋-小屋论坛 开通[通俗易懂]新的BBS已开通,专注收集代码片段、源码资源、Android杂谈。欢迎大家访问。资源小屋:http://www.ziyuanxiaowu.com/portal.php

    2022年7月3日
    47
  • vmware 15 激活码【2022最新】

    (vmware 15 激活码)本文适用于JetBrains家族所有ide,包括IntelliJidea,phpstorm,webstorm,pycharm,datagrip等。IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html…

    2022年4月1日
    139

发表回复

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

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