HDU 2491
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
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.
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)
1 5
2 4
3 6
2
1 5
4 6
0
YES
#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的更多相关文章
- HDU 2491 Priest John's Busiest Day
贪心.. #include<iostream> #include<string.h> #include<math.h> #include <stdio.h&g ...
- 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 ...
- hdu 2491 贪心
#include<stdio.h> #include<stdlib.h> #define N 110000 struct node { int u,v,len,time; }m ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
随机推荐
- System.Web
如果 using System.Web:还是调用不出来其中的类,请在引用的位子添加 System.Web 引用,有的版本不自带这个命名空间. 类: HttpResponse类 用于绘画验 ...
- this指向问题(2)
4.显示绑定 指的是apply.bind.call (1).apply 和 call 相同点: <1> 这两个方法的用途是在特定的作用域中调用函数,实际上等于设置函数体内 this 对象的 ...
- 史上最简单的SpringCloud教程 | 第十一篇: docker部署spring cloud项目
转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springcloud/2017/07/12/sc11-docker/ 本文出自方志朋的博客 一.docker简介 ...
- 关于var和ES6中的let,const的理解
var的作用就不多说了,下面说说var的缺点: 1.var可以重复声明 var a = 1; var a = 5; console.log(a); //5 不会报错 在像这些这些严谨的语言来说,一般是 ...
- Exception occurred during processing request: The given object has a null identifier: com.zsn.crm.Model.SaleVisit; nested exception is org.hibernate.TransientObjectException: The given object has a nu
edit.jsp页面没有加入隐藏字段 id ,导致模型驱动封装时缺少id ,,调用update更新数据库时出错!
- HashMap的使用
HashMap的使用 import java.util.HashMap; import java.util.Iterator; //HashMap<key, value>():键值对的形式 ...
- 使用select2 宽度自适应
加一个CSS属性:style = "width : 100%"
- Ansible学习 Patterns
Ansible中ad-hoc命令格式如下:ansible <pattern_goes_here> -m <module_name> -a <arguments>,P ...
- Linux crontab 实现秒级定时任务
1 crontab 的延时: 原理:通过延时方法 sleep N 来实现每N秒执行. crontab -e 输入以下语句,然后 :wq 保存退出. * * * * * /usr/bin/curl ...
- 《算法》第四版 IDEA 运行环境的搭建
<算法>第四版 IDEA 运行环境的搭建 新建 模板 小书匠 在搭建之初,我是想不到会出现如此之多的问题.我看了网上的大部分教程,都是基于Eclipse搭建的,还没有使用IDEA搭建的教程 ...