Priest John's Busiest Day UVA - 1420

问题

https://vjudge.net/problem/UVA-1420

分析

贪心,不能只看t,应该看最早结束时间来排序,剩下更多的时间进行接下来的任务
例子:
2
1 10
5 9

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long LL;
const int maxn=100000+5;
const double eps=1e-6;
struct Wed{
    int s,t,d;
    bool operator < (const Wed &rhs) const {
        //最早结束时间
        return s+d<rhs.s+rhs.d;
    }
}wedding[maxn];
int n;
int main(void){
    while(scanf("%d",&n)==1 && n){
        for(int i=0;i<n;++i) {
            scanf("%d%d",&wedding[i].s,&wedding[i].t);
            wedding[i].d=(wedding[i].t-wedding[i].s)/2+1;
        }
        sort(wedding,wedding+n);
        int cur=0;
        bool flag=true;
        for(int i=0;i<n;++i){
            cur=max(wedding[i].s,cur)+wedding[i].d;
            if(cur>wedding[i].t) {
                flag=false;
                break;
            }
        }
        if(flag) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值