HUT 排序训练赛 G - Clock
Time Limit: 1000MS | Memory Limit: 32768KB | 64bit IO Format: %I64d & %I64u |
Description
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
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
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
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
21:00
14:05
Source
【题目来源】
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的更多相关文章
- HUT 排序训练赛 F - 水果
Problem's Link Mean: 略. analyse: 使用结构体排序. 首先,定义一个结构体,用来存放输入的数据,然后就是输入,注意:这儿有一个小细节,输入数字,然后紧跟着输入字符串,这时 ...
- 河南多校大一训练赛 G 硬币
题目链接:http://acm.hust.edu.cn/vjudge/contest/125004#problem/G 密码:acm Description 宇航员Bob有一天来到火星上,他有收集硬币 ...
- 2018.7.12训练赛 -G
第二道水题 前边说了很多话,但就最后两段有用. 就是给你一个序列,然后你判断一下这个序列是不是递增的,是就输出yes,否则输出no. 所以以后不管题目看起来多长.多复杂,都要读一遍. 代码就不贴了.
- Contest1592 - 2018-2019赛季多校联合新生训练赛第二场(部分题解)
Contest1592 - 2018-2019赛季多校联合新生训练赛第二场 D 10248 修建高楼(模拟优化) H 10252 组装玩具(贪心+二分) D 传送门 题干 题目描述 C 市有一条东西走 ...
- Contest1585 - 2018-2019赛季多校联合新生训练赛第一场(部分题解)
Contest1585 - 2018-2019赛季多校联合新生训练赛第一场 C 10187 查找特定的合数 D 10188 传话游戏 H 10192 扫雷游戏 C 传送门 题干: 题目描述 自然数中除 ...
- 7.30 正睿暑期集训营 A班训练赛
目录 2018.7.30 正睿暑期集训营 A班训练赛 T1 A.蔡老板分果子(Hash) T2 B.蔡老板送外卖(并查集 最小生成树) T3 C.蔡老板学数学(DP NTT) 考试代码 T2 T3 2 ...
- 10.0.0.55_12-16训练赛部分writeup
0x1 - MISC MISC100 一张帅行的照片 目测是图片隐写,但是binwalk并没有出来,应该是对文件头进行了修改 010editor查看一下,发现在jpg文件尾之后还有大量的数据 而且在灰 ...
- 2016湖南省赛----G - Parenthesis (括号匹配)
2016湖南省赛----G - Parenthesis (括号匹配) Bobo has a balanced parenthesis sequence P=p 1 p 2…p n of lengt ...
- 2016年省赛 G Triple Nim
2016年省赛 G Triple Nimnim游戏,要求开始局面为先手必败,也就是异或和为0.如果n为奇数,二进制下最后一位只有两种可能1,1,1和1,0,0,显然异或和为1,所以方案数为0如果n为偶 ...
随机推荐
- 为啥git会这么差!!!!
删除分支 git push origin --delete Chapater6 可以删除远程分支Chapater6 git branch -d Chapater8 可以删除本地分支(在主分支中) ...
- Markdown 文件如何实现 chm 文件打包
需要借助2个工具,下面的链接都有对应的网址 LME和 hhw, 有不清楚的可以下面评论,7*24小时在线解答问题,也可以加博主微信 首先借助 Markdown To CHM(LME) 工具将Markd ...
- EFK日志搭建
安装java 安装java1.8以上的版本并验证 [root@localhost ~]# yum install java [root@localhost ~]# java -version open ...
- Java的自动拆装箱与Integer的缓存机制
转载请注明原文地址:https://www.cnblogs.com/ygj0930/p/10832303.html 一:基本类型与包装类型 我们知道,Java有8大基本数据类型,4整2浮1符1 ...
- MySQL数据备份概述
MySQL备份类型 热备份.温备份.冷备份 (根据服务器状态) 热备份:读.写不受影响: 温备份:仅可以执行读操作: 冷备份:离线备份:读.写操作均中止: 物理备份与逻辑备份 (从对象来分) 物理备份 ...
- pg 数据库操作
一.pg数据库修改操作 Insert into table (key) values (value) on conflict(主键) do update set key=value; 修改的 valu ...
- maven中,dependency 中的 classifier属性
classifier元素用来帮助定义构件输出的一些附属构件.附属构件与主构件对应,比如主构件是 kimi-app-2.0.0.jar 该项目可能还会通过使用一些插件生成 如 kimi-app-2.0. ...
- Godaddy ssl证书配置到nginx
打开终端,输入以下命令 openssl req -new -newkey rsa:2048 -nodes -keyout domain.key -out domain.csr 生成过程会询问几个常见问 ...
- C#的介绍
C#是一种面向对象的.运行于.net框架上的一种高级程序设计语言. 它的优点在于简单,类型安全,垃圾回收器自动回收内存,封装了许多常用的类,适合快速开发. 它的缺点在于依赖.net框架,跨平台支持有限 ...
- nginx docker 命令: command not found
1. ps: command not found 使用如下命令安装 apt-get update && apt-get -y install procps 2. vim: comman ...