hdu 1209 Clock

Clock

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5870    Accepted Submission(s):
1872

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.

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

题意:n个测试案例,每一个测试案例5个时间,

每一个时间的时针和分针都有一个相对应的角度,

按角度排序,角度排序排在中间的那个时间

{注意: 角度相同的时候   要按时间来排序}

#include <stdlib.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define N 1000
struct SS
{
int hh,mm;
double r;

}f[N];
int cmp(SS a,SS b)
{
if(a.r!=b.r)
return a.r<b.r;
if(a.r==b.r&&a.hh!=b.hh)
return a.hh<b.hh;

}
int main()
{ //freopen("1.txt","r",stdin);
int i,test,m,n;
cin>>test;
while(test--)
{
for(i=0;i<5;i++)
scanf("%d:%d",&f[i].hh,&f[i].mm);
for(i=0;i<5;i++)
{
if(f[i].hh>12)
{
f[i].r=fabs(30.0*(f[i].hh-12)+f[i].mm/2.0-6.0*f[i].mm);

}
else
{
f[i].r=fabs(30.0*f[i].hh+f[i].mm/2.0-6.0*f[i].mm);

}
if(f[i].r>180)
f[i].r=360-f[i].r;

}
sort(f,f+5,cmp);
printf("%02d:%02d\n",f[2].hh,f[2].mm);

}
return 0;
}

时间: 2025-01-15 01:03:14

hdu 1209 Clock的相关文章

杭电 HDU 1209 Clock

Clock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5140    Accepted Submission(s): 1589 Problem Description There is an analog clock with two hands: an hour hand and a minute hand. The two h

hdu 1209 Clock(排序)

题意:按钟表的时针.分针的夹角对5个时间进行升序排序,输出第3个时间 思路:排序 注意:若夹角相同,则按时间进行升序排序 #include<iostream> #include<stdio.h> #include<algorithm> using namespace std; struct node{ int ti[2]; double ang; }a[5]; int cmp(node a,node b){ if(a.ang!=b.ang)return a.ang<

HDU 1209

http://acm.hdu.edu.cn/showproblem.php?pid=1209 水题,按五个时针分针成的锐角从小到大排序,角度相同时间从早到晚,输出中间的那个 时针一小时走30度,一分钟走0.5度,分针一分钟走6度,注意是锐角,大于180要用360减回去,为避免精度出问题统一乘2拒绝小数 #include <iostream> #include <cstdio> #include <cstring> #include <queue> #incl

HDU 5387 Clock

Clock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 422    Accepted Submission(s): 294 Problem Description Give a time.(hh:mm:ss),you should answer the angle between any two of the minute.hou

HDU 5705 Clock (精度控制,暴力)

题意:给定一个开始时间和一个角度,问你下一个时刻时针和分针形成这个角度是几点. 析:反正数量很小,就可以考虑暴力了,从第一秒开始暴力,直到那个角度即可,不会超时的,数目很少,不过要注意精度. 代码如下: #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring> #inclu

HDU 5387 Clock(分数类+模拟)

题意: 给你一个格式为hh:mm:ss的时间,问:该时间时针与分针.时针与秒针.分针与秒针之间夹角的度数是多少. 若夹角度数不是整数,则输出最简分数形式A/B,即A与B互质. 解析: 先计算出总的秒数 S=hh?3600+mm?60+ss 由于秒钟每秒走1°, 所以当前时间,秒钟与12点的度数为 S%360 由于分针每秒走 0.1°, 既然已经计算出总秒数,那么当前时间,分针与12点的度数为 S/10%360 由于时针每秒走(1/120)°.那么当前时间.时针与12点的度数为 S/120%360

HDU 5705 Clock(2016杭电女生专场1004)——角度追及问题

题意是给出一个当前的时间和角度a,问从现在开始的下一个时针和分针形成角度a的时间是多少,时间向下取整. 分析:时针3600s走30°,故120s走1°,分针3600s走360°,故10s走1°,那么每过120s它们就会相差11°,即每过120/11s相差1°,因此设tar是从0:00:00到当前的时间所经过的秒数,cnt也是一样,但是cnt的初始值是a°乘以120/11s,也就是说它是从0:00:00开始的第一个所能形成角度a的时间,然后不断地变更到下一个角度为a的时间即可(所有的时间都先用秒来

HDU 5705 Clock 模拟(精度)

题意:给出时间 HH:MM:SS 角度a 问下一个H和M的角度为a的时刻?时针每小时30度,每分钟30/60度,每秒1/120 (3600,60,1)分针每小时360,每分钟6度,每秒6/60,1/10度; (,720,12)避免精度问题全部乘以120 算出h,m初始角度 h,m之间角度为deg=abs(h-m),暴力枚举几秒后deg==a即可,O(T) #include <bits/stdc++.h> using namespace std; typedef pair<int,int&

hdu 5387 Clock (模拟)

#include<iostream> #include<algorithm> #include<cstring> #include<math.h> #include<stdio.h> #include<map> using namespace std; int gcd(int x,int y) { return y==0?x:gcd(y,x%y); } int main() { int h,m,s; int x,y,z,t; int