Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u

[Submit]   [Go Back]   [Status]

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
 

Source

Asia 2003(Seoul)

【题目来源】

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=41455#problem/G

【题目大意】

输入5个时间点,要求计算时针与分针的夹角,然后比较夹角大小,输出第三大的那个时间点。

【细节】

注意这道题不需要考虑去重,也就是说直接比较输出就可。

还有就是角度相同的时候要比较时针,时针相同时比较分针。

角度最好定义为double型。

当时间大于或等于12时,与12相减然后取绝对值。

【解题思路】首先还是定义一个结构体用来存储输入的数据,然后就是输入,接着计算角度,结构体排序,输出。

【角度计算方法】

大家已经认识了钟表。钟表上的分针、时针在不停息地转动着,两针有时相互重合,有时相互垂直,有时又成一条直线,而求时针、分针形成的各种不同位置所需的时间,就构成了饶有兴趣的时钟问题。

[基础知识]

(1)周角是360°,钟面上有12个大格,每个大格是360°÷12=30°;有60个小格,每个小格是360°÷60=6°。

(2)时针每小时走一个大格(30°),所以时针每分钟走30°÷60=0.5°;分针每小时走60个小格,所以分针每分钟走6°.

一般来说,已知钟面的时刻求时针和分针所成夹角的度数(小于或等于180°的角度),可以找出时针(整时刻)和分针(当前时刻)之间相差的大格或小格数。求出相应度数以后,再减去时针所走的度数(用分针数乘以0.5°)

下面是我的AC代码:

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath> #define eps 1e-6 using namespace std; struct clock
{
char st[];
int h,m;
int time;
double du;
}c[]; bool cmp(clock a,clock b)
{
if(a.du<b.du)
return true;
if(a.du>b.du)
return false;
if(a.du==b.du)
{
return a.time>b.time? false:true;
}
} double cnt(int h,int m)
{
if(h>=) h=h-;
double dh=h*+m*0.5;
double dm=m*; double ma,mi;
ma=max(dh,dm);
mi=min(dh,dm); double ans=ma-mi;
if(ans>=&&ans<=);
else
ans=-ma+mi;
return ans;
} int main()
{
int t;
cin>>t;
while(t--)
{
for(int i=;i<;i++)
{
cin>>c[i].st;
c[i].h=(c[i].st[]-'')*+(c[i].st[]-'');
c[i].m=(c[i].st[]-'')*+(c[i].st[]-'');
c[i].time=c[i].h*+c[i].m;
c[i].du=cnt(c[i].h,c[i].m);
} sort(c,c+,cmp);
cout<<c[].st<<endl;
} return ;
}

HUT 排序训练赛 G - Clock的更多相关文章

  1. HUT 排序训练赛 F - 水果

    Problem's Link Mean: 略. analyse: 使用结构体排序. 首先,定义一个结构体,用来存放输入的数据,然后就是输入,注意:这儿有一个小细节,输入数字,然后紧跟着输入字符串,这时 ...

  2. 河南多校大一训练赛 G 硬币

    题目链接:http://acm.hust.edu.cn/vjudge/contest/125004#problem/G 密码:acm Description 宇航员Bob有一天来到火星上,他有收集硬币 ...

  3. 2018.7.12训练赛 -G

    第二道水题 前边说了很多话,但就最后两段有用. 就是给你一个序列,然后你判断一下这个序列是不是递增的,是就输出yes,否则输出no. 所以以后不管题目看起来多长.多复杂,都要读一遍. 代码就不贴了.

  4. Contest1592 - 2018-2019赛季多校联合新生训练赛第二场(部分题解)

    Contest1592 - 2018-2019赛季多校联合新生训练赛第二场 D 10248 修建高楼(模拟优化) H 10252 组装玩具(贪心+二分) D 传送门 题干 题目描述 C 市有一条东西走 ...

  5. Contest1585 - 2018-2019赛季多校联合新生训练赛第一场(部分题解)

    Contest1585 - 2018-2019赛季多校联合新生训练赛第一场 C 10187 查找特定的合数 D 10188 传话游戏 H 10192 扫雷游戏 C 传送门 题干: 题目描述 自然数中除 ...

  6. 7.30 正睿暑期集训营 A班训练赛

    目录 2018.7.30 正睿暑期集训营 A班训练赛 T1 A.蔡老板分果子(Hash) T2 B.蔡老板送外卖(并查集 最小生成树) T3 C.蔡老板学数学(DP NTT) 考试代码 T2 T3 2 ...

  7. 10.0.0.55_12-16训练赛部分writeup

    0x1 - MISC MISC100 一张帅行的照片 目测是图片隐写,但是binwalk并没有出来,应该是对文件头进行了修改 010editor查看一下,发现在jpg文件尾之后还有大量的数据 而且在灰 ...

  8. 2016湖南省赛----G - Parenthesis (括号匹配)

    2016湖南省赛----G - Parenthesis (括号匹配)   Bobo has a balanced parenthesis sequence P=p 1 p 2…p n of lengt ...

  9. 2016年省赛 G Triple Nim

    2016年省赛 G Triple Nimnim游戏,要求开始局面为先手必败,也就是异或和为0.如果n为奇数,二进制下最后一位只有两种可能1,1,1和1,0,0,显然异或和为1,所以方案数为0如果n为偶 ...

随机推荐

  1. dapperDemo

    dapperDemo 下载链接:http://pan.baidu.com/s/1geQHXPT

  2. Vue-Cli 指南

    构建项目: vue create 文件夹名称 运行项目:(README文件查询) npm run serve

  3. java--Date时间

    Date: 表示特定的瞬间,精确到毫秒,通过方法设定自己所表示的时间,可以表示任意的时间 System.currentTimeMillis() :返回的当前系统时间, 1970-1-1 至今的毫秒数 ...

  4. js中数组的迭代方法

    1.forEach 让数组的每一项做一件事 var arr = [1,2,3,4,5] arr.forEach(function(item,index){ console.log(item) }) 2 ...

  5. 原生ajax中readyState中的含义以及HTTP协议状态码的含义

    xmlhttp.readyState的值及解释: 0:请求未初始化(还没有调用 open()). 1:请求已经建立,但是还没有发送(还没有调用 send()). 2:请求已发送,正在处理中(通常现在可 ...

  6. 打包工具webpack和热加载深入学习

    本次小编呢,为大家带来一篇深入了解打包工具 webpack. 我们今天使用的是 webpack3.8.1版本的,我们学习使用 3.8.1更稳定些,并学习自己如何配置文件,最新版本不需要自己配置文件,但 ...

  7. MySQL Other--mysql_config_editor学习使用

    mysql_config_editor工具 为避免MySQL明文密码出现在脚本或命令中,从MySQL5.6开始提供了mysql_config_editor工具,可以将数据库连接信息进行加密并保存到用户 ...

  8. shell脚本遇到问题"$'\r': command not found"

    shell脚本写得一切正常,但是一执行就报错: line: XXX "$'\r': command not found" 问题原因:文件格式问题(虽然在window和linux上选 ...

  9. Linux计划任务管理

    计划任务 类型:     一次性计划任务     周期性计划任务      一次性计划任务 前提:  atd服务必须运行 [root@wei init.d]# yum -y install at   ...

  10. sublimeText3和phpstrom使用

    一.sublimtext3 下载地址:http://www.sublimetext.com/3 1.1      安装package control 插件,用来获取和管理插件(sublime包管理工具 ...