Clock

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5870    Accepted Submission(s):
1872

Problem Description
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
题意:n个测试案例,每一个测试案例5个时间,
每一个时间的时针和分针都有一个相对应的角度,
按角度排序,角度排序排在中间的那个时间
{注意: 角度相同的时候   要按时间来排序}

#include <stdlib.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define N 1000
struct SS
{
int hh,mm;
double r;

}f[N];
int cmp(SS a,SS b)
{
if(a.r!=b.r)
return a.r<b.r;
if(a.r==b.r&&a.hh!=b.hh)
return a.hh<b.hh;

}
int main()
{ //freopen("1.txt","r",stdin);
int i,test,m,n;
cin>>test;
while(test--)
{
for(i=0;i<5;i++)
scanf("%d:%d",&f[i].hh,&f[i].mm);
for(i=0;i<5;i++)
{
if(f[i].hh>12)
{
f[i].r=fabs(30.0*(f[i].hh-12)+f[i].mm/2.0-6.0*f[i].mm);

}
else
{
f[i].r=fabs(30.0*f[i].hh+f[i].mm/2.0-6.0*f[i].mm);

}
if(f[i].r>180)
f[i].r=360-f[i].r;

}
sort(f,f+5,cmp);
printf("%02d:%02d\n",f[2].hh,f[2].mm);

}
return 0;
}

hdu 1209 Clock的更多相关文章

  1. hdu 1209 Clock(排序)

    题意:按钟表的时针.分针的夹角对5个时间进行升序排序,输出第3个时间 思路:排序 注意:若夹角相同,则按时间进行升序排序 #include<iostream> #include<st ...

  2. HDU 1209

    http://acm.hdu.edu.cn/showproblem.php?pid=1209 水题,按五个时针分针成的锐角从小到大排序,角度相同时间从早到晚,输出中间的那个 时针一小时走30度,一分钟 ...

  3. HDU 5705 Clock(模拟,分类讨论)

    Clock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submi ...

  4. HDU——1393Weird Clock(水题,注意题意)

    Weird Clock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  5. HDU 5705 Clock (精度控制,暴力)

    题意:给定一个开始时间和一个角度,问你下一个时刻时针和分针形成这个角度是几点. 析:反正数量很小,就可以考虑暴力了,从第一秒开始暴力,直到那个角度即可,不会超时的,数目很少,不过要注意精度. 代码如下 ...

  6. HDU 5387 Clock

    题意:给一个时间,求三个时针之间的夹角,分数表示. 解法:算算算.统一了一下分母. 代码: #include<stdio.h> #include<iostream> #incl ...

  7. HDU 5387 Clock (MUT#8 模拟)

    [题目链接]:pid=5387">click here~~ [题目大意]给定一个时间点.求时针和分针夹角,时针和秒针夹角,分针和秒针夹角 模拟题,注意细节 代码: #include&l ...

  8. HDU 5387 Clock(分数类+模拟)

    题意: 给你一个格式为hh:mm:ss的时间,问:该时间时针与分针.时针与秒针.分针与秒针之间夹角的度数是多少. 若夹角度数不是整数,则输出最简分数形式A/B,即A与B互质. 解析: 先计算出总的秒数 ...

  9. HDU 5705 Clock(2016杭电女生专场1004)——角度追及问题

    题意是给出一个当前的时间和角度a,问从现在开始的下一个时针和分针形成角度a的时间是多少,时间向下取整. 分析:时针3600s走30°,故120s走1°,分针3600s走360°,故10s走1°,那么每 ...

随机推荐

  1. greenplum(postgresql) 数据字典

    greenplum是基于postgresql开发的分布式数据库,里面大部分的数据字典是一样的.我们在维护gp的时候对gp的数据字典比较熟悉,特此分享给大家.在这里不会详细介绍每个字典的内容,只会介绍常 ...

  2. Ubuntu18.04开机动画(bootsplash)安装

    一.搜索喜欢的主题 1.通过软件源搜索,这个比较简单但是没有太喜欢的.-----------------------------------------------------------pipci@ ...

  3. Bzoj 3333 高级打字机(主席树)

    3333 高级打字机 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 大师 Master 题目描述 Description 早苗入手了最新的高级打字机.最新款自然有着与以往不同的功能 ...

  4. TensorFlow(一):准备

    我的环境:win10+python3.6.4(64位) 一:安装python 根据自己的电脑下载python(32位或者64位)-->安装教程 安装好python后记得配置pip源,使用官方的源 ...

  5. PHP全栈学习笔记27

    数组概述,类型,声明,遍历,输出,获取数组中最后一个元素,删除重复数组,获取数组中指定元素的键值,排序,将数组中的元素合成字符串. 数组概述,数组是存储,管理和操作一组变量. 数组类型为一维数组,二维 ...

  6. PHP全栈学习笔记20

    thinkphp概述,thinkphp项目构建流程,thinkphp项目结构,thinkphp配置,thinkphp控制器,thinkphp模型,thinkphp视图,thinkphp的内置模板引擎. ...

  7. 【原创】go语言学习(五)函数详解1

    目录 1.函数介绍 2.多返回值和可变参数 3.defer语句 4.内置函数介绍 1.函数介绍 1.1定义: 有输⼊入.有输出,⽤用来执⾏行行⼀一个指定任务的代码块. func functionnam ...

  8. 二分算法题目训练(四)——Robin Hood详解

    codeforces672D——Robin Hood详解 Robin Hood 问题描述(google翻译) 我们都知道罗宾汉令人印象深刻的故事.罗宾汉利用他的射箭技巧和他的智慧从富人那里偷钱,然后把 ...

  9. jmeter压测过程中报java.lang.NoClassDefFoundError: org/bouncycastle/jce/provider/BouncyCastleProvider

    由于在java中添加了第三方安全策略文件,具体请看https://www.cnblogs.com/mrjade/p/10886378.html,导致在用jmeter压测过程中会遇到以下错误 解决办法: ...

  10. C语言中怎样定义能够保存16进制整数的变量

    可以通过int 或long int存储,16进制整数说到底还是整数,16进制只是一种记数方式.例如,int x=0x16;十六进制(hexadecimal)只是计算机中数据的一种表示方法,规则是“逢十 ...