hdu 2491 贪心
#include<stdio.h>
#include<stdlib.h>
#define N 110000
struct node {
int u,v,len,time;
}ma[N];
int cmp(const void *a,const void *b){
return (*(struct node *)a).time-(*(struct node *)b).time;
}
int main() {
int n,i,k;
while(scanf("%d",&n),n) {
for(i=0;i<n;i++) {
scanf("%d%d",&ma[i].u,&ma[i].v);
ma[i].len=(ma[i].v-ma[i].u)/2+1;//记录仪式进行的时间长度
ma[i].time=ma[i].u+ma[i].len;//从第一次仪式开始到结束时间的长度
}
qsort(ma,n,sizeof(ma[0]),cmp);
k=ma[0].time;//初始化为仪式的结束时间
for(i=1;i<n;i++) {
if(ma[i].v-ma[i].len<k)//如果当前的仪式的结束-其长度《上一次的结束世间直接退出
break;
if(k>ma[i].u)//如果上一次的结束时间高于本次的结束时间,就加上其长度
k+=ma[i].len;
else
k=ma[i].time;//否则就等于本次的结束时间
}
if(i==n)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
hdu 2491 贪心的更多相关文章
- 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 5289-Assignment 贪心,ST表
题目: http://acm.hdu.edu.cn/showproblem.php?pid=5289 Assignment Time Limit: 4000/2000 MS (Java/Others) ...
- hdu 4803 贪心/思维题
http://acm.hdu.edu.cn/showproblem.php?pid=4803 话说C++还卡精度么? G++ AC C++ WA 我自己的贪心策略错了 -- 就是尽量下键,然后上 ...
- hdu 1735(贪心) 统计字数
戳我穿越:http://acm.hdu.edu.cn/showproblem.php?pid=1735 对于贪心,二分,枚举等基础一定要掌握的很牢,要一步一个脚印走踏实 这是道贪心的题目,要有贪心的意 ...
- hdu 4974 贪心
http://acm.hdu.edu.cn/showproblem.php?pid=4974 n个人进行选秀,有一个人做裁判,每次有两人进行对决,裁判可以选择为两人打分,可以同时加上1分,或者单独为一 ...
- hdu 4982 贪心构造序列
http://acm.hdu.edu.cn/showproblem.php?pid=4982 给定n和k,求一个包含k个不相同正整数的集合,要求元素之和为n,并且其中k-1的元素的和为完全平方数 枚举 ...
- HDU 2307 贪心之活动安排问题
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2037 今年暑假不AC Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 1052 贪心+dp
http://acm.hdu.edu.cn/showproblem.php?pid=1052 Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS ...
- HDU 2111 Saving HDU【贪心】
解题思路:排序后贪心,和fatmouse's trade 类似 Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: ...
随机推荐
- java根据内容生成二维码图片
package util; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; ...
- DevExpress14.1.2 xe XE6 高速安装
之前在在网上下载的DevExpress14.1.2 xe-XE6都是一个个包文件.须要一个个去查找编译安装,并且须要有一定的顺序要求. 所下面载了好久了都没有安装. 近期在网上找了个旧版的安装方法.以 ...
- 2016.04.07,英语,《Vocabulary Builder》Unit 11
cant, from the Latin verbs canere and cantare, meaning 'sing'. by way of French, add an h to the roo ...
- python spark 决策树 入门demo
Refer to the DecisionTree Python docs and DecisionTreeModel Python docs for more details on the API. ...
- Path Sum II 总结DFS
https://oj.leetcode.com/problems/path-sum-ii/ Given a binary tree and a sum, find all root-to-leaf p ...
- ASP.NET Core Web API下事件驱动型架构的实现
mvp 原创博文:http://www.cnblogs.com/daxnet/p/8082694.html
- Python中断言与异常的区别
异常,在程序运行时出现非正常情况时会被抛出,比如常见的名称错误.键错误等. 异常: >>> s Traceback (most recent call last): File &qu ...
- oracle数据库rman备份与还原
我是oracle 界的小白,由于公司领导要求,不得不硬着头皮在网上找rman备份还原的方法,废话不多说,具体看例子(window) 运行CMD: rman target 管理员账号/密码@orcl 备 ...
- RedHat/CentOS 大文件拆分及合并与md5验证
[root@tdh55 mnt]# cd /opt/[root@tdh55 opt]# ll -h-rw-r--r--. 1 root root 7.5G May 12 11:19 TDH-Image ...
- Swift - 关键字(typealias、associatedtype)
Typealias typealias 是用来为已经存在的类型重新定义名字的,通过命名,可以使代码变得更加清晰.使用的语法也很简单,使用typealias 关键字像使用普通的赋值语句一样,可以将某个已 ...