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需要 ...
随机推荐
- ruby语言仅仅是昙花一现
Ruby语言本身存在非常久了,在国内一直没火过.非常多人仅仅是知道有这样的语言,会的人少之又少.不论什么一种语言坚持十来年的发展,变得越来越好,一定有它不平常的地方.不能任意的去比較语言本身的好与坏. ...
- A*寻路算法的实现
原理:http://www.cppblog.com/christanxw/archive/2006/04/07/5126.html 算法理论请到原理这个传送门,代码中的注释,已经比较详细,所以我不会讲 ...
- Open Source RTOS
http://www.osrtos.com/ Name License Platforms Description Last updated FreeRTOS Modified GPL MSP ...
- [置顶] 初识window.location.search
window.location.search是从当前URL的?号开始的字符串 如:http://www.domain.com/item?id=0064014 它的search就是?id=0064014
- 《转》如何成为一个牛逼的C/C++程序员?
原地址:http://blog.csdn.net/langeldep/article/details/6333562 这个题目的噱头太大,要真的写起来, 足够写一本书了. 本人是过来人, 结合自身的体 ...
- Codeforces Round #296 (Div. 2) A B C D
A:模拟辗转相除法时记录答案 B:3种情况:能降低2,能降低1.不能降低分别考虑清楚 C:利用一个set和一个multiset,把行列分开考虑.利用set自带的排序和查询.每次把对应的块拿出来分成两块 ...
- Activity数据传输到服务
activity数据接口负责启动该服务包.service获取数据.手术. 详细demo如下面: package com.example.android_service_trance; import a ...
- Nginx 负载均衡-加权轮询策略剖析
本文介绍的是客户端请求在多个后端服务器之间的均衡,注意与客户端请求在多个nginx进程之间的均衡相区别(Nginx根据每个工作进程的当前压力调整它们获取监听套接口的几率,那些当前比较空闲的工作进程有更 ...
- 项目实践中--Git服务器的搭建与使用指南(转)
一.前言 Git是一款免费.开源的分布式版本控制系统,用以有效.高速的处理从很小到非常大的项目版本管理.在平时的项目开发中,我们会使用到Git来进行版本控制. Git的功能特性: 从一般开发者的角度来 ...
- gem5 设定checkpiont以及从checkpoint开始运行
同spec2006中间bzip2一个例子,如何设置checkpoint .以及从checkpoint继续以启动运行.这样做的目的是为了,采纳automic运行N指令,然后detailed运行M指令. ...