杭电1209Clock
来源:互联网 发布:unity3d 剧情怎么做 编辑:程序博客网 时间:2024/06/05 10:06
Clock
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5296 Accepted Submission(s): 1645
Problem 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.
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
300:00 01:00 02:00 03:00 04:0006:05 07:10 03:00 21:00 12:5511:05 12:05 13:05 14:05 15:05
Sample Output
02:0021:0014:05
Source
Asia 2003(Seoul)
求出时针和分针的夹角的绝对值,排序后输出角度为中间的那个时间,要求如果夹角一样,则时间比较小的排在前边:
附代码:
#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>using namespace std;struct node{int hour;int minute;double angle;}t[10];int cmp(node a,node b){if(a.angle==b.angle)return a.hour*60+a.minute<b.hour*60+b.minute;return a.angle<b.angle ;}int i,j,k,l,m,n;int main(){while(~scanf("%d",&k)){while(k--){for(i=0;i<5;i++){scanf("%d:%d",&t[i].hour,&t[i].minute);int hour=t[i].hour;if(hour>=12)hour-=12;t[i].angle=fabs(hour*30+t[i].minute*1.00/2-t[i].minute*1.00*6);t[i].angle=min(360-t[i].angle,t[i].angle);}sort(t,t+5,cmp);printf("%02d:%02d\n",t[2].hour,t[2].minute);//被double惯坏了,错了两边后发现输出的是.2d,虽然结果相同.}}return 0;}
0 0
- 杭电1209Clock
- 杭电 HDU 1209 Clock
- 杭电OJ 5387 Clock
- 杭电OJ 1209题clock 解题报告
- 杭电OJ 题 1209 Clock 解题报告
- 杭电 HDU ACM 1393 Weird Clock
- 杭电OJ题 1393 Weird Clock解题报告
- 杭电OJ第4256题 The Famous Clock
- 【2016杭电女生赛1004】【枚举 数学解方程】Clock 下一时刻时针分针恰成角度
- HDU 1209 ( Clock )
- HDU 1209 Clock
- hdu 1209 Clock
- clock
- clock
- clock
- Clock
- CLOCK
- clock
- poj 2699 The Maximum Number of Strong Kings 【二分 + 竞赛图建模判断是否满流】
- 深入理解java内存模型
- 我对于今目标的反思
- jsp 九大内置对象
- 黑马程序员-java基础-数组深入
- 杭电1209Clock
- Android Api Demos登顶之路(七十一)Graphics-->Cliping
- 谈谈JavaScript中function多重理解
- 杭电1001-Sum Problem
- java中HashMap,LinkedHashMap,TreeMap,HashTable的区别
- ORACLE索引回表访问
- PHP中数组合并的两种方法及区别介绍 array_merge +
- Linux开机显示命令行
- 《霜冷长河》之壮士2