Priest John's Busiest Day

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1734    Accepted Submission(s): 479

Problem 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.

 
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
 
Source

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
struct node{
int u,v,m,h;
}que[];
bool cmp(struct node t1,struct node t2){
if(t1.m==t2.m)
return t1.u<t2.u;
else
return t1.m<t2.m;
}
int main(){
int n;
while(scanf("%d",&n)!=EOF){
if(n==)
break;
for(int i=;i<n;i++){
scanf("%d%d",&que[i].u,&que[i].v);
que[i].h=(que[i].v-que[i].u)/+;
que[i].m=que[i].u+que[i].h;
}
sort(que,que+n,cmp);
int flag=;
for(int i=;i<n-;i++){
if(que[i].m>=que[i+].m){
flag=;
break;
}
if(que[i].m<que[i+].u)
continue;
double temp=que[i].m-que[i+].u;
que[i+].m=temp+que[i+].h+que[i+].u;
}
if(flag)
printf("NO\n");
else
printf("YES\n"); }
return ;
}

HDU 2491的更多相关文章

  1. HDU 2491 Priest John's Busiest Day

    贪心.. #include<iostream> #include<string.h> #include<math.h> #include <stdio.h&g ...

  2. HDU 2491 Priest John's Busiest Day(贪心)(2008 Asia Regional Beijing)

    Description John is the only priest in his town. October 26th is the John's busiest day in a year be ...

  3. hdu 2491 贪心

    #include<stdio.h> #include<stdlib.h> #define N 110000 struct node { int u,v,len,time; }m ...

  4. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  5. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  6. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  7. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  8. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  9. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

随机推荐

  1. C# unchecked运算符

    一.C# unchecked运算符 unchecked运算符用于取消整型算术运算和转换的溢出检查. 二.提示 默认情况下,都是unchecked选项.因此,只有在需要把几个未检查的代码行放在一个明确标 ...

  2. util.Date与sql.Date转换

    一. 时间类型 1.  sql包下, Date:只有年月日. Time:只有时分秒. Timestamp:表示时间戳,有年月日时分秒,以及毫秒. 2.  util包下, Date是sql包下三种时间类 ...

  3. orale 10g和11g中的自动统计任务

    orale 10g和11g中的自动统计任务 博客分类:  数据库相关/oracle   1)  先来看下oracle 10g中的自动统计任务的问题. 从Oracle Database 10g开始,Or ...

  4. python中字符串编码方式小结

    Python2中字符串的类型有两种:str和unicode,其中unicode是统一编码方式,它使得字符跟二进制是一一对应的,因此所有其他编码的encode都从unicode开始,而其他编码方式按照相 ...

  5. Gulp工具

    Gulp是一个基于node开发的构建工具. gulp本身是不进行任何构建任务,是通过gulp的一些列插件完成: gulp-less  编译LESS文件: gulp-autoprefix  添加css私 ...

  6. mysql 自定义不规则排序

    mysql按id的指定顺序进行排序,以前解决过一次,后来忘了,记录一下 SELECT * FROM `table` WHERE id<6 order by field(id,3,5,1,2,4)

  7. python学习之列表和元组

    配置环境:python 3.6 python编辑器:pycharm,代码如下: #!/usr/bin/python # -*- coding: UTF-8 -*- # list:是一种有序的集合,可以 ...

  8. is 和 == 的区别,utf和gbk的转换,join用法

    is 和 == 的区别 # is 比较的是内存地址 # == 比较的是值 a = 'alex' b = 'alex' #int,str(小数据池)会被缓存,为了节约内存 print(id(a),id( ...

  9. phpstorm调试配置 Xdebug

    这已经楼主第二次因为phpstorm的调试配置折腾了几个小时,这次一定要记下来!!! 以Xdebug chrome浏览器为例 一:安装 JetBrains IDE Support 二:安装 Xdebu ...

  10. Android onConfigurationChanged 收不到回调

    我返现,90度横屏 旋转到270度横屏onConfigurationChanged 是收不到回掉的.尽管清单里面声明了什么: android:configChanges="orientati ...