Priest John's Busiest Day

· · 题解

这道题并不难

好像和蓝书的题目描述不一样,所以直接贪心就行了。

越早开会越好,当然每一场会开一半的时间最好,多抢时间去开其他的会议

AC代码如下

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
struct vode
{
    int s;
    int t;
    int val;
}a[200005];
bool cmp(vode x,vode y)
{
    return x.s+x.val<y.s+y.val;
}
int main()
{
    int n;
    while(scanf("%d",&n) && n>0)
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d",&a[i].s,&a[i].t);
            a[i].val=(a[i].t-a[i].s)/2+1;
        }
        sort(a+1,a+1+n,cmp);
        int flag=0;
        int nowtime=0;
        for(int i=1;i<=n;i++)
        {
            nowtime=max(nowtime,a[i].s)+a[i].val;
            if(nowtime>a[i].t)
            {
                flag=1;
                break;
            }
        }
        if(flag==1)
        {
            printf("NO\n");
        }
        else
        {
            printf("YES\n");
        }
    }
    return 0;
}