主题链接:

problemId=1680" target="_blank">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1680

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

版权声明:本文博主原创文章,博客,未经同意不得转载。

ZOJ 2680 Clock()数学的更多相关文章

  1. ZOJ 1122 Clock(模拟)

    Clock Time Limit: 2 Seconds      Memory Limit: 65536 KB You are given a standard 12-hour clock with ...

  2. zoj 1889 ones 数学

    Ones Time Limit: 2 Seconds      Memory Limit: 65536 KB Given any integer 0 <= n <= 10000 not d ...

  3. ZOJ Saddle Point 数学思维题

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5564   根据它的定义是行最小,列最大. 可以证明鞍点是唯一的. ...

  4. POJ 2363 Blocks (ZOJ 1910) 数学

    杨宗纬的歌"这一路走来" 还蛮好听的,这首歌静静的躺在我的音乐盒某个阴暗的角落里,今天随机播放才发现的,哈哈. 数学一直是硬伤...... -------------------- ...

  5. 数学+高精度 ZOJ 2313 Chinese Girls' Amusement

    题目传送门 /* 杭电一题(ACM_steps 2.2.4)的升级版,使用到高精度: 这次不是简单的猜出来的了,求的是GCD (n, k) == 1 最大的k(1, n/2): 1. 若n是奇数,则k ...

  6. POJ 3100 &amp; ZOJ 2818 &amp; HDU 2740 Root of the Problem(数学)

    题目链接: POJ:id=3100" style="font-size:18px">http://poj.org/problem? id=3100 ZOJ:http ...

  7. ZOJ Problem Set - 3593 拓展欧几里得 数学

    ZOJ Problem Set - 3593 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3593 One Person ...

  8. ZOJ 3230 Solving the Problems(数学 优先队列啊)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3230 Programming is fun, Aaron is ...

  9. ZOJ 1494 Climbing Worm 数学水题

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=494 题目大意: 一只蜗牛要从爬上n英寸高的地方,他速度为u每分钟,他爬完u需要 ...

随机推荐

  1. python 内存泄露的诊断 - 独立思考 - ITeye技术网站

    python 内存泄露的诊断 - 独立思考 - ITeye技术网站 python 内存泄露的诊断 博客分类: 编程语言: Python Python多线程Blog.net  对于一个用 python ...

  2. Windows8和MacOS10.9双系统安装及Mac经常使用软件安装--联想E49A

    前提 本篇内容所描写叙述的内容仅仅适合联想E49A笔记本,经过本篇的内容之后,对于Mac OS 10.9的使用达到正常工作使用的标准,完美度已经比較好了. 结果例如以下:显卡.网卡(RTL8168). ...

  3. bzoj1497(最小割)

    传送门:最大获利 题意:建立n个中转站,每个花费P[i],有m个用户,使用Ai和Bi中转站可获利Ci,问最终建立哪几个中转站使获利最大? 分析:根据最大权闭合图建图,用户群和中转站为带权的点集,用户群 ...

  4. Codeforces 196 C. Paint Tree

    分治.选最左上的点分给根.剩下的极角排序后递归 C. Paint Tree time limit per test 2 seconds memory limit per test 256 megaby ...

  5. 读取生产环境go语言的最佳实践展示

    近期看了一篇关于go产品开发最佳实践的文章,go-in-procution.作者总结了他们在用go开发过程中的非常多实际经验,我们非常多事实上也用到了.鉴于此,这里就简单的写写读后感,兴许我也争取能将 ...

  6. C#操作Cookie

    /* 创建者:菜刀居士的博客  * 创建日期: 2014年09月02号  * 功能:操作Cookie  *  */ namespace Net.String.ConsoleApplication { ...

  7. Nutch+HBase

    Nutch+HBase 当我们为nutch的架构发愁的时候,nutch的开发人员送来了nutchbase.我一些简单的测试表明,在hadoop0.20.1和hbase0.20.2上,稍加修改可以运行起 ...

  8. cocos2d-x 旅程開始--(实现瓦片地图中的碰撞检測)

    转眼隔了一天了,昨天搞了整整一下午加一晚上,楞是没搞定小坦克跟砖头的碰撞检測,带着个问题睡觉甚是难受啊!还好今天弄成功了.只是感觉程序不怎么稳定啊.并且发现自己写的东西让我重写一遍的话我肯定写不出来. ...

  9. Java8高中并发

    Java8中学并发 本文翻译自:http://jaxenter.com/lean-concurrency-in-java-8-49924.html 转载请注明出处:http://blog.csdn.n ...

  10. C++习题 虚函数-计算图形面积

    C++习题 虚函数-计算图形面积 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 122  Solved: 86 [cid=1143&pid=6 ...