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单继承的弥补——接口
接口主要用来实现多重继承,它是常量和方法的集合,这些方法只有声明没有实现,即接口本身是抽象的,系统默认用abstract修饰. 1.接口的定义: public interface A{ int A=1 ...
- A. Music(Codeforces Round #315 (Div. 2) 求最大的容纳量)
A. Music time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- 【Python学习笔记】-APP图标显示未读消息数目
以小米手机系统为例,当安装的某个APP有未读消息时,就会在该APP图标的右上角显示未读消息的数目.本文主要解说怎样用Python语言实现图标显示未读消息的数目.首先,还是要用到Python中PIL库, ...
- CodeForces 651A(水题)
Friends are going to play console. They have two joysticks and only one charger for them. Initially ...
- shp系列(二)——利用C++进行shp文件的读(打开)
1.各数据类型及其字节数 BYTE 1; char 1; short 2; int 4; double 8; 2.位序big和little及其转换 对于位序是big的 ...
- 20. Valid Parentheses[E]有效的括号
题目 Given a string containing just the characters '(',')','[',']','{' and '}',determine if the input ...
- BZOJ 1507 splay
写完维修数列 这不是水题嘛233333 //By SiriusRen #include <cstdio> #include <cstring> #include <alg ...
- CentOS6.5下nginx-1.8.1.tar.gz的单节点搭建(图文详解)
不多说,直接上干货! [hadoop@djt002 local]$ su root Password: [root@djt002 local]# ll total drwxr-xr-x. root r ...
- lua lfs库
lfs.attributes(filepath [, aname]) 获取路径指定属性 lfs.chdir(path) 改变当前工作目录,成功返回true,失败返回nil加上错误信息 l ...
- MVP演化论
本文是翻译MVP: Model-View-Presenter The Taligent Programming Model for C++ and Java(Mike Potel)文章的摘要.该文介绍 ...