| 4328 - Priest John's Busiest Day Asia - Beijing - 2008/2009 | ||||
| Submit | Ranking | |||
John is the only priest in his town. October 26th is the John's busiest day in a year because there is an old legend in the town that the couple who get married on that day will be forever blessed by the God of Love. This year N couples plan to get married on the blessed day. The i -th couple plan to hold their wedding from time Si to time Ti . According to the traditions in the town, there must be a special ceremony on which the couple stand before the priest and accept blessings. Moreover, this ceremony must be longer than half of the wedding time and can't be interrupted. Could you tell John how to arrange his schedule so that he can hold all special ceremonies of all weddings?
Please note that:
John can not hold two ceremonies at the same time.
John can only join or leave the weddings at integral time.
John can show up at another ceremony immediately after he finishes the previous one.
Input
The input consists of several test cases and ends with a line containing a zero. In each test case, the first line contains a integer N
(1
N
100, 000) indicating the total number of the weddings. In the next N lines, each line contains two integers Si and Ti (
0
Si < Ti
2147483647 ).
Output
For each test, if John can hold all special ceremonies, print ``YES"; otherwise, print ``NO".
Sample Input
3 1 5 2 4 3 6 2 1 5 4 6 0
Sample Output
NO YES
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct Node
{
int x,y,mid,mintime,end;
};
Node a[110000];
bool cmp(Node h,Node k)
{
if(h.mid!=k.mid) return h.mid<k.mid;
return h.x<k.x;
}
int main()
{
int n;
while(scanf("%d",&n)==1&&n)
{
for(int i=0;i<n;i++)
{
scanf("%d%d",&a[i].x,&a[i].y);//时间段
a[i].mintime=(a[i].y-a[i].x)/2+1;//最少需要的时间
a[i].mid=a[i].x+a[i].mintime;
}
sort(a,a+n,cmp);
// for(int i=0;i<n;i++) cout<<a[i].x<<"..."<<a[i].mid<<"..."<<a[i].y<<endl;
int flag=1;
a[0].end=a[0].mid;
for(int i=1;i<n;i++)
{
int j=i-1;
int t=a[j].end>a[i].x?a[j].end:a[i].x;
//cout<<"i="<<i<<"..."<<t<<"..."<<a[i].mintime<<"..."<<a[i].y<<endl;
if(a[i].mid>=a[j].end&&(t+a[i].mintime<=a[i].y))
{
a[i].end=t+a[i].mintime;
}
else
{
flag=0;
break;
}
}
if(flag) printf("YES/n");
else printf("NO/n");
}
return 0;
}
/*
3
1 2
3 5
4 5
*/
在一个小镇上,神父John面临着一年中最忙碌的一天——十月二十六日,因为传说这天结婚的情侣会得到爱神的永恒祝福。今年有N对情侣计划在这天举行婚礼,每场婚礼都有特定的时间段,而根据传统,神父必须主持一段不低于婚礼时长一半的特殊仪式且不能中断。本篇探讨如何合理安排这些婚礼仪式。
2135

被折叠的 条评论
为什么被折叠?



