CF967A(细节模拟)

题面:

A. Mind the Gap
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

The first line of input contains two integers nn and ss (1n1001≤n≤100, 1s601≤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 (0h230≤h≤23, 0m590≤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.

Output

Print 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
Copy
6 60
0 0
1 20
3 21
5 0
19 30
23 40
Output
Copy
6 1
Input
Copy
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
Copy
24 50
Input
Copy
3 17
0 30
1 0
12 0
Output
Copy
0 0

Note

In 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.


题目意思:飞机都会进行n次降落,每次降落的时间为xh,ymin,在两两飞机降落之间要插入一次起飞,起飞和降落之间都要间隔s分钟,每次起飞和降落都需要花费1分钟的死时间,问你最早要插入的时间为什么时候。
 题目分析:这题是一个挺考细节的题目。因为小时和分钟同时出现,因此,为了方便计算,我们可以将时间统一化成分钟,最后再重新化成小时分钟即可。
    首先,当s+1没有超过最开始的时间的时候,证明是最早的起飞是可以发生在0 0时刻的。其次,如果不能满足最开始的时刻,则需要枚举所有的时间,判断前一个时间+s*2+2是否大于后面的时刻,如果小于,就将前一个时间+s+1输出即可。
    最后,倘若所有都不满足,则需要在最后的时间+s+1即可。
    (ps:需要主意好边界的处理,否则很容易错误)

#include <bits/stdc++.h>
using namespace std;
struct num{
    int hours,mins;
}q[105];
int times[105];
int main()
{
    int n,s;
    cin>>n>>s;
    for(int i=1;i<=n;i++){
        cin>>q[i].hours>>q[i].mins;
        times[i]=q[i].hours*60+q[i].mins;
    }
    bool flag=true;
    if(times[1]-s-1>=0){
        cout<<0<<" 0"<<endl;
        return 0;
    }
    for(int i=2;i<=n;i++){//否则枚举所有的时间点
        if(times[i-1]+s*2+2>times[i]) continue;//如果前一个时刻不满足条件则继续枚举
        else{
            int tmp=times[i-1]+s+1;
            cout<<tmp/60<<" "<<tmp%60<<endl;//满足条件则按小时分钟输出
            flag=false;
            break;
        }
    }
    if(flag){//如果全部时刻均不满足,则在最后+s+1后输出
        int tmp=times[n]+s+1;
        cout<<tmp/60<<" "<<tmp%60<<endl;
    }
}

posted @ 2018-04-30 12:28  ChenJr  阅读(305)  评论(0编辑  收藏  举报