简单模拟之Mind the Gap

这道题大致意思就是给你一张飞机着陆的时间表,着陆行程有N个,让你去插入一个飞机起飞的最早时间,不过有一个硬性要求就是这个飞机起飞的时间与它前后两个着陆的飞机的时间差严格大于题目给的时间T

这道题我也是都了很久题意以及推了样例才搞懂的 刚开始我一直以为T是用来这个飞机往返的时间 所以第三个样例就不能得出答案,这个T根本不是这么用的。后来换了一个思路,我们先去计算在凌晨飞机起飞是否合适,再去计算其他时间端两端的时间差是否严格大于T*2+1(飞机起飞需要花费一分钟啊,废话)都不满足,那么飞机起飞只能被安排在所有的行程后面了,但是我还是WA了六次,后来看了给的范围才发现给的行程超过了24,我简直对我自己无语,居然以为按照一天24小时的去写代码,晕,还是太菜。

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

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

#include<bits/stdc++.h>
#define lson rt<<1,l,m
#define rson rt<<1|1,m+1,r
#define mem(a,b) memset(a,b,sizeof(a))
#define LL long long
#define inf 0x3f3f3f3f
using namespace std;

const int maxn=1e4;

int h[maxn],m[maxn];
int cha(int hq,int mq,int hn,int mn)
{
    int ans=0;
    if(mn>=mq)
        ans+=mn-mq;
    else
    {
        ans+=mn+60-mq;
        hn--;
    }
    ans+=(hn-hq)*60;
    return ans;
}
int main()
{
    int n,mi,i;
    while(~scanf("%d%d",&n,&mi))
    {
        mem(h,0);
        mem(m,0);
        for(i=1; i<=n; i++)
            scanf("%d%d",&h[i],&m[i]);
        int flag=0,pos,x;
        int first=0;
        if(m[1]>=60)
        {
            h[1]+=m[1]/60;
            m[1]%=60;
        }
        first+=h[1]*60+m[1];
        if(first>mi)
            puts("0 0");
        else
        {
            for(i=1; i<=n; i++)
            {
                x=cha(h[i-1],m[i-1],h[i],m[i]);
                //cout<<x<<endl;
                if(x>=mi*2+2)
                {
                    pos=i;
                    flag=1;
                    break;
                }
            }
            if(!flag)
                pos=n;
            else
                pos--;
            //cout<<pos<<endl;
            m[pos]+=mi+1;
            if(m[pos]>=60)
            {
                h[pos]+=m[pos]/60;
                m[pos]%=60;
            }
            printf("%d %d\n",h[pos],m[pos]);
        }
    }
    return 0;
}
/*
6 60
0 0
1 20
3 21
5 0
19 30
23 40

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

3 17
0 30
1 0
12 0
*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值