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. iOS开发网络缓存原理

    一.关于同一个URL的多次请求 有时候,对同一个URL请求多次,返回的数据可能都是一样的,比如服务器上的某张图片,无论下载多少次,返回的数据都是一样的. 上面的情况会造成以下问题 (1)用户流量的浪费 ...

  2. 泉五培训Day3

    T1 家庭作业 题目 [问题描述] 小P为了能高效完成作业,规定每项作业花一个单位时间. 他的学习日从0时刻开始,有100000个单位时间.在任一时刻,他都可以选择编号1~N的N项作业中的任意一项作业 ...

  3. 【模板时间】◆模板·III◆ 单调子序列

    ◆模板·III◆ 单调子序列 以前只知道DP用 O(n2) 的做法,现在才发现求单调子序列方法好多…… ◇ 模板简述 单调子序列包括 升序/降序/非升序/非降序 子序列.主要题型如下: ①在原串中找到 ...

  4. JS中常犯错误

    01.==与=== 释: 在JavaScript中使用三等号来判断两个条件是否相等.使用等于关系运算符时,只有两边的条件相等时,结果才为真,否则就是假.注意等于关系运算符并不只是判断 数字类型的数据, ...

  5. MySQL另类的备份恢复方法——innodb可传输表空间

      Preface       There're many ways in backing up or migrating data from one server to another one.Lo ...

  6. js面向(基于)对象编程—类(原型对象)与对象

    JS分三个部分: 1. ECMAScript标准--基础语法 2. DOM  Document Object Model 文档对象模型 3. BOM  Browser Object Moldel 浏览 ...

  7. php-5.6.26源代码 - PHP文件汇编成opcode、执行

    文件 php-5.6.26/Zend/zend.c ZEND_API int zend_execute_scripts(int type TSRMLS_DC, zval **retval, int f ...

  8. 子查询,用户管理,pymysql使用

    当我们的一条记录 分散不同的表中时,就需要进行多表查询例如 一对一 一对多 多对多 1.笛卡尔积查询 意思就是将两个表中的所有数据 全部关联在一起例如A表有两条 B表有三条 一共有6条会产生大量的错误 ...

  9. 准备篇(三)Makefile

    Makefile 也是蛮多的, 嵌入式的Makefile也是很重要的,所以单独开一个分支.

  10. Codeforces Round 97B 点分治

    B. Superset time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...