跳到正文

题解

Priest John's Busiest Day

zzr8178541919约 2 分钟
原文
文章信息与版本

文章信息

发布
2019年10月22日
收录
2025年12月12日
更新
2026年11月11日
篇幅
约 2 分钟
获赞
3
题目
UVA1420

版本

  1. v1当前

这道题并不难

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

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

AC代码如下

C++
#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;
}
 
原文