Codeforce---------Mind the Gap

These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts 11 minute.
He was asked to insert one takeoff in the schedule. The takeoff takes 11 minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least ss minutes from both sides.
Find the earliest time when Arkady can insert the takeoff.
InputThe first line of input contains two integers nn and ss (1≤n≤1001≤n≤100, 1≤s≤601≤s≤60) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff.
Each of next nn lines contains two integers hh and mm (0≤h≤230≤h≤23, 0≤m≤590≤m≤59) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is 00 00). These times are given in increasing order.OutputPrint two integers hh and mm — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
Examples

Input

6 60
0 0
1 20
3 21
5 0
19 30
23 40
Output
6 1
Input
16 50
0 30
1 20
3 0
4 30
6 10
7 50
9 30
11 10
12 50
14 30
16 10
17 50
19 30
21 10
22 50
23 59
Output
24 50
Input
3 17
0 30
1 0
12 0
Output
0 0
NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.
In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than 2424 hours to insert the takeoff.
In the third example Arkady can insert the takeoff even between the first landing.
题目大意:第一行输入降落的飞机数和每俩架飞机之间需要相差的飞机s。
接下来的每行输入的是降落飞机的时间,前一个是小时,后一个是分钟,在降落和起飞之间都要间隔s的时间,降落和起飞都要1分钟。输出的是第一个可以起飞的时间
思路:由于时间既有小时又有分钟,所以这里统一拿分钟表示,分情况讨论,先看能不能在0时0分起飞(在第一架飞机降落前是否有s+1的时间),然后看能不能在中间起飞(俩个飞机降落之间的时间是否有2*s+2的时间),如果枚举到了最后一个飞机,都不行的话,直接在最后一个飞机降落后s+1时间后起飞。

#include <iostream>
#include <cstdio>

using namespace std;

const int N = 100 + 10;

int times[N];

int main(){
	int n, s;
	cin >> n >> s;

for (int i = 1; i <= n; i ++){
		int a, b;
		scanf("%d%d",&a, &b);
		times[i] = a * 60 + b;
	}

if (times[1] - s - 1 >= 0){
		cout << 0 << " " << 0 << endl;
		return 0;
	}

bool success = true;
	for (int i = 2; i <= n; i ++){
		if (times[i - 1] + 2 * s + 2 > times[i])  continue;
		else{
			int x = times[i - 1] + s + 1;
			printf("%d %d\n",x / 60, x % 60);
			success = false;
			break;
		} 
	}
	if (success){
		int x = times[n] + s + 1;
		printf("%d %d\n",x / 60, x % 60);
	}

return 0;
}
发布了106 篇原创文章 · 获赞 67 · 访问量 5441

猜你喜欢

转载自blog.csdn.net/qq_45772483/article/details/104741091
GAP
GAP