POJ3927 Priest John's Busiest Day
来源:互联网 发布:帝国cms小说系统 编辑:程序博客网 时间:2024/05/17 04:21
Priest John's Busiest Day
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 533 Accepted: 171
Description
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.
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)
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
NOYES
Source
Beijing 2008
贪心,记录每场ceremony必经的时间点,并按其排序,如果没有冲突,那么方案可行,接下来的操作就是普通的任务安排了。。。
#include <iostream>#include <cstdio>#include <cstring>#include <vector>#include <algorithm>using namespace std;struct mony{int s,t;int ts,tt;int last;friend bool operator <(mony a,mony b){if(a.ts != b.ts)return a.ts < b.ts;return a.tt < b.tt;}};int n;vector<mony>mm;void init(){mm.clear();mony tk;for(int i = 0; i < n; i++){int a,b;scanf("%d%d",&a,&b);tk.s = a;tk.t = b;tk.last = (b-a)/2+1;if((b-a)%2==0){tk.ts = (b-a)/2+a-1;tk.tt = tk.ts+2;}else{tk.ts = (b-a-1)/2+a;tk.tt = tk.ts+1;}mm.push_back(tk);}sort(mm.begin(),mm.end());}void solve(){bool flag = 1;int now_s,now_t,last_t=mm[0].s+mm[0].last;for(int i = 1; i < n; i++){now_s = max(mm[i].s,last_t);if(mm[i].t-now_s < mm[i].last){flag = 0;break;}last_t = min(now_s+mm[i].last,mm[i].t);}if(flag) cout<<"YES"<<endl;else cout<<"NO"<<endl;}int main(){while(~scanf("%d",&n)&&n){init();solve();}return 0;}
- POJ3927 Priest John's Busiest Day
- Priest John's Busiest Day
- POJ 3683 Priest John's Busiest Day
- hdu Priest John's Busiest Day
- Pku 3683 Priest John's Busiest Day
- POJ 3683 Priest John's Busiest Day
- poj 3683 Priest John's Busiest Day
- poj 3683 Priest John's Busiest Day
- HDU2491(Priest John's Busiest Day)贪心
- POJ 3683 Priest John's Busiest Day
- poj 3683 Priest John's Busiest Day
- hdu 2491 Priest John's Busiest Day
- POJ 3683 Priest John's Busiest Day
- POJ 3683 Priest John's Busiest Day
- HDU 2491 Priest John's Busiest Day
- UVALive - 4328 Priest John's Busiest Day
- POJ 3927 Priest John's Busiest Day
- UVA1420 - Priest John's Busiest Day
- IOS开发--C语言基础篇
- 将项目符号定义在屏幕的任意地方
- 使用DirectShow采集图像
- openGL 深度测试
- C++_运算符重载
- POJ3927 Priest John's Busiest Day
- Linux文件操作学习总结
- 组队赛 131002 Regionals 2011, North America - Rocky Mountain
- 手机号码正则表达式
- ios关闭键盘
- GIS毕业生就业状况调查报告
- 老鼠与毒药问题
- android 全屏显示
- hibernate之面向性能的粒度细分