陈老师的多校联合20140818||Uvalive 5683 模拟
来源:互联网 发布:预算计价软件 编辑:程序博客网 时间:2024/05/16 17:17
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3684
Percy likes to be punctual. So much so that he always keeps three watches with him, so that he can be sure exactly what the time is. However, Percy's having a bad day. He found out that one of his watches was giving the wrong time. What's worse, when he went to correct the watch, he corrected the wrong one! That is, one watch was running x minutes behind (where x480) and he wound one of the other watches x minutes forward. He now has three watches reading three different times, and hence is in serious danger of being tardy. Can you help Percy by writing a program that takes in the three times displayed on the watches and returns the correct time?
Input
The input begins with an integer T indicating the number of cases that follow ( 0 < T < 100). Each of the following T lines contains one test case, made up of three readings, separated by single space characters:H1:M1 H2:M2 H3:M3 In each reading H1, H2, H3 represent the hours displayed ( 0 < H1, H2, H3 < 13), and M1, M2,M3 represent the minutes displayed ( 0M1, M2, M3 < 60).
If the number of minutes is less than 10, a leading 0 is perpended.
Output
For each test case, one line should be produced, formatted exactly as follows: "The correct time is Hi:Mi". If the number of minutes is less than 10, a leading 0 should be added. If the number of hours is less than 10, a leading 0 should NOT be added. If it is impossible to tell the time from the three readings, print the string: "Look at the sun".
Sample Input
35:00 12:00 10:0011:59 12:30 1:0112:00 4:00 8:00
Sample Output
The correct time is 5:00The correct time is 12:30Look at the sun
解题思路:x最大不过8小时,我们吧时间调到一个24小时内找三者中间点,若相差不是4小时即可。
#include <stdio.h>#include <iostream>#include <algorithm>#include <string.h>using namespace std;int judge[8],sum[8],h[4],m[4],a[4];int ab(int x){ if(x<0) return -x; return x;}int ji_suan(int x,int y,int z,int &k){ if(ab(x-y)==ab(y-z)) { k = y; return ab(x-y); } else if(ab(x-z)==ab(y-z)) { k = z; return ab(x-z); } else if(ab(x-y)==ab(z-x)) { k = x; return ab(x-y); } else { k = -1 ; return -1; }}int main(){ int T; scanf("%d",&T); while(T--) { int a[4]; for(int i=1; i<=3; i++) scanf("%d:%d",&h[i],&m[i]); for(int i=1; i<=3; i++) a[i] = h[i]*60+m[i]; int flag = 0; //24小时内换算 judge[1] = ji_suan(a[1],a[2],a[3],sum[1]); judge[2] = ji_suan(a[1]+720,a[2],a[3],sum[2]); judge[3] = ji_suan(a[1],a[2]+720,a[3],sum[3]); judge[4] = ji_suan(a[1],a[2],a[3]+720,sum[4]); judge[5] = ji_suan(a[1]-720,a[2],a[3],sum[5]); judge[6] = ji_suan(a[1],a[2]-720,a[3],sum[6]); judge[7] = ji_suan(a[1],a[2],a[3]-720,sum[7]); for(int i=1; i<8; i++) if(judge[i]>0) { flag = 1; if(judge[i] == 240)//正好是一个环 { printf("Look at the sun\n"); break; } else { printf("The correct time is %d:%02d\n",sum[i]/60,sum[i]%60); break; } } if(!flag) printf("Look at the sun\n"); } return 0;}/**995:00 12:00 10:0011:59 12:30 1:0112:00 4:00 8:001:01 2:01 3:01**/
- 陈老师的多校联合20140818||Uvalive 5683 模拟
- 陈老师的多校联合20140815 ||uvalive 5881 区间处理
- UVALive 5691 二分图匹配||陈老师的多校联合20140818 J题
- 陈老师的多校联合 20140809
- 陈老师的多校联合 I题 二分
- 陈老师的多校联合20180808 map映射字符串
- 陈老师的多校联合 20140809 C题
- 陈老师的多校联合 20140808 E题
- 陈老师的多校联合20140816||spoj10237 bfs
- 陈老师的多校联合20140816||SPOJ AMR11B 三角形的有向面积
- 陈老师的多校联合 D题 字符串处理起来挺麻烦
- 陈老师的多校联合2010811c题||09年武汉站||hdu3232
- 陈老师的多校联合2009年武汉站D题 ||hdu 3033
- 陈老师的多校联合20140816A题||spoj 10228 动态规划
- 陈老师的多校联合20140811||HDU 3236 ||2009年武汉站G题 01背包问题
- 山东多校联合模拟赛 Day2
- 陈老师的艺术人生
- 【HDU 4891 多校联合】The Great Pan【模拟】
- hdu-3784-继续xxx定律
- 杭电 2084 数塔 (DP)
- linux发送post请求
- 断点续传 ASIHTTPRequest
- poj1200 Crazy Search,字符串hash or 后缀数组
- 陈老师的多校联合20140818||Uvalive 5683 模拟
- Interactive Machine Translation
- HDU 1860 统计字符
- 统计学习--学习笔记(二)
- 堆和栈
- X264 CBP
- 杭电1248 寒冰王座
- java操作mysql的增删改查
- c++ vector 用法