您的位置:首页 > 其它

Codeforces Round #544(Div.3) A. Middle of the Contest题解报告

2019-03-11 12:43 741 查看
A. Middle of the Contest
time limit per test1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

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

总结

这道题特别的简单,但为什么又要花时间来写这篇博客呢?因为这道题的做题经历特别有教育意义。因为自己思路上的大意,导致花了特别多的时间。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: