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 ;
}

最新文章

  1. 35.两链表的第一个公共结点[Find the first common node of two linked list]
  2. php CLI 模式下的传参方法
  3. nginx(3、负载均衡)
  4. apple配置WIFI热点
  5. LabVIEW串口通信的一个例子-串口&quot;示波器&quot;
  6. python3字符串格式化
  7. 使用Java反射(Reflect)、自定义注解(Customer Annotation)生成简单SQL语句
  8. 一维树状数组(HD1166)
  9. 语句(语句分类及if语句)
  10. 我用的比较少的CSS选择器
  11. asp.net 开发注意的几点
  12. iOS 编程小知识 之 本地化
  13. 一张图理清ASP.NET Core启动流程
  14. 用js写动态时钟 2017-03-23
  15. 自己用 Netty 实现一个简单的 RPC
  16. 使用datagrid时json的格式
  17. Google资深工程师深度讲解Go语言完整教程
  18. JAVA核心技术I---JAVA基础知识(二进制文件读写和zip文件读写)
  19. php完美匹配邮箱、链接地址和电话号码
  20. 理解 LSTM 网络

热门文章

  1. 2019国际VR/AR暨3D显示大会内容总结
  2. cc.isChildClassOf 判断两个类的继承关系
  3. Excel单元格锁定及解锁
  4. 个人项目 python实现
  5. 如何用StatSVN统计SVN服务器某项目的代码量
  6. java-log4j配置
  7. 【HttpServlet】HttpServlet类
  8. python测试开发django-73.django视图 CBV 和 FBV
  9. win10台式机rtl8188eu(FW 150 UM V2.0)无线网卡无法连接wifi(无法连接到这个网络)
  10. Slf4j 打日志的问题 Exception 没有堆栈信息