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

hdu 1209 Clock的更多相关文章

  1. hdu 1209 Clock(排序)

    题意:按钟表的时针.分针的夹角对5个时间进行升序排序,输出第3个时间 思路:排序 注意:若夹角相同,则按时间进行升序排序 #include<iostream> #include<st ...

  2. HDU 1209

    http://acm.hdu.edu.cn/showproblem.php?pid=1209 水题,按五个时针分针成的锐角从小到大排序,角度相同时间从早到晚,输出中间的那个 时针一小时走30度,一分钟 ...

  3. HDU 5705 Clock(模拟,分类讨论)

    Clock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submi ...

  4. HDU——1393Weird Clock(水题,注意题意)

    Weird Clock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

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

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

  6. HDU 5387 Clock

    题意:给一个时间,求三个时针之间的夹角,分数表示. 解法:算算算.统一了一下分母. 代码: #include<stdio.h> #include<iostream> #incl ...

  7. HDU 5387 Clock (MUT#8 模拟)

    [题目链接]:pid=5387">click here~~ [题目大意]给定一个时间点.求时针和分针夹角,时针和秒针夹角,分针和秒针夹角 模拟题,注意细节 代码: #include&l ...

  8. HDU 5387 Clock(分数类+模拟)

    题意: 给你一个格式为hh:mm:ss的时间,问:该时间时针与分针.时针与秒针.分针与秒针之间夹角的度数是多少. 若夹角度数不是整数,则输出最简分数形式A/B,即A与B互质. 解析: 先计算出总的秒数 ...

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

    题意是给出一个当前的时间和角度a,问从现在开始的下一个时针和分针形成角度a的时间是多少,时间向下取整. 分析:时针3600s走30°,故120s走1°,分针3600s走360°,故10s走1°,那么每 ...

随机推荐

  1. spring boot 实现多个 interceptor 并指定顺序

    首先我们创建Interceptor,实现HandlerInterceptor覆写方法:一.下面我创建了三个拦截器:MyInterceptor,UserInterceptor,StudentInterc ...

  2. Oracle语句中IN和=的区别有哪些?

    Oracle语句中IN和=的区别有: 1.首先应用范围不一样:in 可以理解为是范围内的选择:= 只有一个.例如: select sno, sname from t1 where sno in ('s ...

  3. [转]C++重载()(强制类型转换运算符)

    在 C++ 中,类型的名字(包括类的名字)本身也是一种运算符,即类型强制转换运算符. 类型强制转换运算符是单目运算符,也可以被重载,但只能重载为成员函数,不能重载为全局函数.经过适当重载后,(类型名) ...

  4. TensorFlow(十五):使用inception-v3实现各种图像识别

    上代码: import tensorflow as tf import os import numpy as np import re from PIL import Image import mat ...

  5. NetworkX系列教程(1)-创建graph

    小书匠Graph图论 研究中经常涉及到图论的相关知识,而且常常面对某些术语时,根本不知道在说什么.前不久接触了NetworkX这个graph处理工具,发现这个工具已经解决绝大部分的图论问题(也许只是我 ...

  6. iptables一些练习

    iptables 一些小练习 可以参考之前的一起食用 https://www.cnblogs.com/lovesKey/p/10909633.html 允许来自192.168.0.0/16网段的地址来 ...

  7. 编程用sort进行排序,然后从最后一个元素开始判断,去重

    a=[,,,,,,,,,,,,,,] a.sort() last=a[-] ,-,-): if last==a[i]: del a[i] else: last=a[i] print(a)

  8. linux 编写定时任务,查询服务是否挂掉

    shell 脚本 #!/bin/bash a=`netstat -unltp|grep fdfs|wc -l` echo "$a" if [ "$a" -ne ...

  9. Python3 输入和输出(二)

    接上一节 1.读写文件的模式图 将字符串写入到文件 foo.txt 中: #!/usr/bin/python3 # 打开一个文件f = open("/tmp/foo.txt", & ...

  10. Nginx之URL重写(rewrite)配置

    Nginx URL重写(rewrite)配置及信息详解1)if判断指令 语法为if(condition){…}     #对给定的条件condition进行判断.如果为真,大括号内的rewrite指令 ...