ZOJ 2680 Clock()数学
主题链接: 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()数学的更多相关文章
- ZOJ 1122 Clock(模拟)
Clock Time Limit: 2 Seconds Memory Limit: 65536 KB You are given a standard 12-hour clock with ...
- zoj 1889 ones 数学
Ones Time Limit: 2 Seconds Memory Limit: 65536 KB Given any integer 0 <= n <= 10000 not d ...
- ZOJ Saddle Point 数学思维题
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5564 根据它的定义是行最小,列最大. 可以证明鞍点是唯一的. ...
- POJ 2363 Blocks (ZOJ 1910) 数学
杨宗纬的歌"这一路走来" 还蛮好听的,这首歌静静的躺在我的音乐盒某个阴暗的角落里,今天随机播放才发现的,哈哈. 数学一直是硬伤...... -------------------- ...
- 数学+高精度 ZOJ 2313 Chinese Girls' Amusement
题目传送门 /* 杭电一题(ACM_steps 2.2.4)的升级版,使用到高精度: 这次不是简单的猜出来的了,求的是GCD (n, k) == 1 最大的k(1, n/2): 1. 若n是奇数,则k ...
- POJ 3100 & ZOJ 2818 & HDU 2740 Root of the Problem(数学)
题目链接: POJ:id=3100" style="font-size:18px">http://poj.org/problem? id=3100 ZOJ:http ...
- ZOJ Problem Set - 3593 拓展欧几里得 数学
ZOJ Problem Set - 3593 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3593 One Person ...
- ZOJ 3230 Solving the Problems(数学 优先队列啊)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3230 Programming is fun, Aaron is ...
- ZOJ 1494 Climbing Worm 数学水题
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=494 题目大意: 一只蜗牛要从爬上n英寸高的地方,他速度为u每分钟,他爬完u需要 ...
随机推荐
- Python天天美味(25) - 深入理解yield
Python天天美味(25) - 深入理解yield - CoderZh - 博客园 Python天天美味(25) - 深入理解yield yield的英文单词意思是生产,刚接触Python的时候 ...
- [IDEs]Eclipse设置花括号样式
用惯Vistual Studio,在使用Eclipse时发现有很多东西还是挺不习惯,第一个就要解决花括号的样式 步骤: 1.Windows->Preferences->Java->C ...
- 计算机视觉与模式识别代码合集第二版three
计算机视觉与模式识别代码合集第二版three Topic Name Reference code Optical Flow Horn and Schunck's Optical Flow ...
- RIA Test:try catch 对 Error #1009 (无法访问空对象引用的属性或方法)的处理
功能: 实现登录账户的强制登录, 用If 判断当前账户是否可用.若可用,则跳出if体直接登录,若不可用,则进入If体点击 “强制登录” 按钮. 问题:如果不可用,则if 条件中的对象不可见,这样程序会 ...
- c++重载ostream的实现
#include <iostream> using namespace std; class Point{ public: Point(int _x = 0, int _y = 0, in ...
- HDU1754_I Hate It(线段树/单点更新)
解题报告 题意: 略 思路: 单点替换,区间最值 #include <iostream> #include <cstring> #include <cstdio> ...
- hdu1695(莫比乌斯反演)
传送门:GCD 题意:求[1,n],[1,m]gcd为k的对数. 分析:莫比乌斯入反演门题,gcd(x,y)==k等价于gcd(x/k,y/k)==1,求出[1,n][1,m]互质的对数,在减去[1, ...
- Android数据库高手秘籍(一)——SQLite命令
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/38461239 要想熟练地操作不论什么一个数据库.最最主要的要求就是要懂SQL语言, ...
- [置顶] C++学习书单
关于C++的书太多了,很容易让人没有头绪.一直想整理下,把这些书列个书单出来,直到今天才动手.希望我的经验能给后来的初学者一点帮助. 1.<C++程序设计教程> 钱能 很多学校把这本书选做 ...
- WebView混合开发
现在开发APP的方式变化,不在是传统的APP开发了,有很多的APP慢慢的转向混合模式的开发,使用WebView是传统开发模式转向混合模式的桥梁工具,结合了很多的Web前端开发界面,使得开发的速度加快, ...