Codeforces Round #544(Div.3) A. Middle of the Contest题解报告
Polycarp is going to participate in the contest. It starts at h1:m1h1:m1h1:m1 and ends at h2:m2h2:m2h2:m2. It is guaranteed that the contest lasts an even number of minutes (i.e. m1m_1m1%222=m2m_2m2%222, where xxx%yyy is xxx modulo yyy). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Polycarp wants to know the time of the midpoint of the contest. For example, if the contest lasts from 10:0010:0010:00 to 11:0011:0011:00 then the answer is 10:3010:3010:30, if the contest lasts from 11:10 to 11:1211:1211:12 then the answer is 11:1111:1111:11.
Input
The first line of the input contains two integers h1h_1h1 and m1m_1m1 in the format hh:mmhh:mmhh:mm.
The second line of the input contains two integers h2h_2h2 and m2m_2m2 in the same format (hh:mm)(hh:mm)(hh:mm).
It is guaranteed that 0 ≤\leq≤ h1,h2h_1,h_2h1,h2 ≤\leq≤ 23 and 0 ≤\leq≤ m1,m2m_1,m_2m1,m2 ≤\leq≤ 59.
It is guaranteed that the contest lasts an even number of minutes (i.e. m1m_1m1%222=m2m_2m2%222, where xxx%yyy is xxx modulo yyy). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Output
Print two integers h3h_3h3 and m3m_3m3 (000 ≤\leq≤ h3h_3h3 ≤\leq≤ 232323,0≤m3≤590\leq m_3 \leq 590≤m3≤59) corresponding to the midpoint of the contest in the format hh:mmhh:mmhh:mm. Print each number as exactly two digits (prepend a number with leading zero if needed), separate them with ‘:’.
Examples
input |
---|
10:00 |
11:00 |
output |
10:30 |
input |
---|
11:10 |
11:12 |
output |
11:11 |
input |
---|
01:02 |
03:02 |
output |
02:02 |
题目大意
求一天中任意两个时间的中间时间。
解题思路
因为两个时刻的分钟没有确定的相对大小,那么我就把两个时刻都转换为对应的分钟数,那么中间时刻就为初始时刻加上两个时刻分钟数之差的一半。然后再转换为对应的时刻即可。之前想的思路错误就在直接取余计算中间时刻的时间,忽视了分钟数还有可能对小时产生的进位。
AC代码
#include<bits/stdc++.h> const int Max_N=1e3+6; using namespace std; int main() { int h1,h2,m1,m2; char c; cin>>h1>>c>>m1; cin>>h2>>c>>m2; int mid=(h2*60+m2)-(h1*60+m1); mid/=2; h2=(h1*60+m1+mid)/60; m2=(h1*60+m1+mid)%60; printf("%02d:%02d",h2,m2); }
总结
这道题特别的简单,但为什么又要花时间来写这篇博客呢?因为这道题的做题经历特别有教育意义。因为自己思路上的大意,导致花了特别多的时间。
- Codeforces Round #544(Div. 3)--A Middle of the Contest(简单模拟题)
- The University of Chicago Invitational Programming Contest 2012 解题报告
- POJ 3331 The Idiot of the Year Contest! 高精度阶乘
- 2014百度之星复赛解题报告:The Game of Coins
- hdu 5381 The sum of gcd 原来有个算法叫莫队 2015 Multi-University Training Contest 8
- ZOJ 3872 Beauty of Array (The 12th Zhejiang Provincial Collegiate Programming Contest )
- POJ-2553-The Bottom of a Graph 解题报告
- [题解] HDU 2128 Tempter of the Bone II(迭代加深)
- The 2014 ACM-ICPC Asia Mudanjiang Regional Contest 【部分题解】
- The 9th Zhejiang Provincial Collegiate Programming Contest->Problem :K-Yet Another Story of Rock-pap
- HDU 4898 The Revenge of the Princess’ Knight ( 2014 Multi-University Training Contest 4 )
- Oracle AWR 报告中 No data exists for this section of the report 说明
- The 5th(2010) ACM Programming Contest of HUST
- 2009 CSW Contest of JLU 解题报告(新生可看)
- 372. 在O(1)时间复杂度删除链表节点 (delete-node-in-the-middle-of-singly-linked-list)(c++)----lintcode面试题之链表
- 2017 Multi-University Training Contest - Team 8:Fleet of the Eternal Throne(AC自动机)
- POJ 3331 The Idiot of the Year Contest! 高精度阶乘
- In the middle of nowhere
- 2017 Multi-University Training Contest - Team 8 Fleet of the Eternal Throne
- UVA 539 - The Settlers of Catan 解题报告