首页 > 代码库 > hdu 1209 Clock
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
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.
#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;
}
hdu 1209 Clock