【Codeforces】967A Mind the Gap【暴力】

【Codeforces】967A Mind the Gap

【题目大意】

给你一个由h(小时)和m(分钟)组成的飞机起飞的序列,让你找一个时间,使这个时间距相邻两架飞机起飞的时间至少S+1,找出最早的。

【题解】

这题很水,就枚举一个位置然后插入就可以了,注意开头和结尾就OK了。

【代码如下】

#include<cstdio>
using namespace std;
int n,S;
int main(){
//  freopen("A.in","r",stdin);
//  freopen("A.out","w",stdout);
    scanf("%d%d",&n,&S);
    int lsth=0,lstt=-S-1,lst=-S-1;//开头
    int nowh=0,nowt=0,now=0;
    for(int i=1;i<=n;i++){
        scanf("%d%d",&nowh,&nowt);
        now=nowh*60+nowt;
        if(now-lst>=2*S+2){
            nowh=lsth+(lstt+S+1)/60;
            nowt=(lstt+S+1)%60;
            printf("%d %d\n",nowh,nowt);
            return 0;
        }
        lst=now;lsth=nowh;lstt=nowt;
    }
    nowh=lsth+(lstt+S+1)/60;//结尾
    nowt=(lstt+S+1)%60;
    printf("%d %d\n",nowh,nowt);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41357771/article/details/80148919