[Usaco2006 Open]County Fair Events 参加节日庆祝
Description
Farmer John has returned to the County Fair so he can attend the special events (concerts, rodeos, cooking shows, etc.). He wants to attend as many of the N (1 <= N <= 10,000) special events as he possibly can. He's rented a bicycle so he can speed from one event to the next in absolutely no time at all (0 time units to go from one event to the next!). Given a list of the events that FJ might wish to attend, with their start times (1 <= T <= 100,000) and their durations (1 <= L <= 100,000), determine the maximum number of events that FJ can attend. FJ never leaves an event early.
有N个节日每个节日有个开始时间,及持续时间. 牛想尽可能多的参加节日,问最多可以参加多少. 注意牛的转移速度是极快的,不花时间.
Input
Line 1: A single integer, N.
Lines 2..N+1: Each line contains two space-separated integers, T and L, that describe an event that FJ might attend.
Output
- Line 1: A single integer that is the maximum number of events FJ can attend.
Sample Input
7
1 6
8 6
14 5
19 2
1 8
18 3
10 6
Sample Output
4
首先按结束时间排序,然后一路搜下去,发现一个节日的开始时间在所记录的结束时间之后,就参加这个节日,同时更新记录的结束时间(典型贪心思想)
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using namespace std;
inline int read(){
int x=0,f=1;char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+ch-'0';
return x*f;
}
inline void print(int x){
if (x>=10) print(x/10);
putchar(x%10+'0');
}
const int N=1e4;
struct AC{
int l,r;
void join(int x,int y){l=x,r=y;}
bool operator <(const AC &x)const{return r<x.r;}
}A[N+10];
int main(){
int n=read();
for (int i=1,x,y;i<=n;i++) x=read(),y=read(),A[i].join(x,x+y);
sort(A+1,A+1+n);
int x=A[1].r,ans=1;
for (int i=2;i<=n;i++) if (A[i].l>=x) x=A[i].r,ans++;
printf("%d\n",ans);
return 0;
}
[Usaco2006 Open]County Fair Events 参加节日庆祝的更多相关文章
- BZOJ 1664: [Usaco2006 Open]County Fair Events 参加节日庆祝( dp )
先按时间排序( 开始结束都可以 ) , 然后 dp( i ) = max( dp( i ) , dp( j ) + 1 ) ( j < i && 节日 j 结束时间在节日 i 开 ...
- 1664: [Usaco2006 Open]County Fair Events 参加节日庆祝
1664: [Usaco2006 Open]County Fair Events 参加节日庆祝 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 255 S ...
- bzoj1664 [Usaco2006 Open]County Fair Events 参加节日庆祝
Description Farmer John has returned to the County Fair so he can attend the special events (concert ...
- 【BZOJ】1664: [Usaco2006 Open]County Fair Events 参加节日庆祝(线段树+dp)
http://www.lydsy.com/JudgeOnline/problem.php?id=1664 和之前的那题一样啊.. 只不过权值变为了1.. 同样用线段树维护区间,然后在区间范围内dp. ...
- 【动态规划】bzoj1664 [Usaco2006 Open]County Fair Events 参加节日庆祝
将区间按左端点排序. f(i)=max{f(j)+1}(p[j].x+p[j].y<=p[i].x && j<i) #include<cstdio> #incl ...
- bzoj 1664: [Usaco2006 Open]County Fair Events 参加节日庆祝【dp+树状数组】
把长度转成右端点,按右端点排升序,f[i]=max(f[j]&&r[j]<l[i]),因为r是有序的,所以可以直接二分出能转移的区间(1,w),然后用树状数组维护区间f的max, ...
- County Fair Events
先按照结束时间进行排序,取第一个节日的结束时间作为当前时间,然后从第二个节日开始搜索,如果下一个节日的开始时间大于当前的时间,那么就参加这个节日,并更新当前时间 #include <bits/s ...
- BZOJ-USACO被虐记
bzoj上的usaco题目还是很好的(我被虐的很惨. 有必要总结整理一下. 1592: [Usaco2008 Feb]Making the Grade 路面修整 一开始没有想到离散化.然后离散化之后就 ...
- 小结:线段树 & 主席树 & 树状数组
概要: 就是用来维护区间信息,然后各种秀智商游戏. 技巧及注意: 一定要注意标记的下放的顺序及影响!考虑是否有叠加或相互影响的可能! 和平衡树相同,在操作每一个节点时,必须保证祖先的tag已经完全下放 ...
随机推荐
- Effective Java Profiling With Open Source Tools
https://www.infoq.com/articles/java-profiling-with-open-source
- oracle dtrace for linux
https://docs.oracle.com/cd/E37670_01/E37355/html/ol_config_dtrace.html#
- spring mvc 集成freemarker模板
主要使用到的jar 文件:spring mvc +freemarker.jar 第一步:spring mvc 集成 freemarker <!-- 定义跳转的文件的前后缀 ,视图模式配置--&g ...
- 2>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _calloc 已经在 LIBCMTD.lib(dbgcalloc.obj) 中定义
使用VS2010,在FireBreath里面调用ortp库和Speex库.编译的时候出现错误: 2>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _ca ...
- 奥斯卡·王尔德十大经典语录
10不够真诚是危急的,太真诚则绝对是致命的.--摘自<身为艺术家的评论者> "A little sincerity is a dangerous thing, and a gre ...
- 浅谈asp.net通过本机cookie仿百度(google)实现搜索input框自己主动弹出搜索提示
对于通过用户输入关键词实现自己主动弹出相关搜索结果,这里本人给两种解决方式,用于两种不同的情形. 常见方法是在数据库里建一个用户搜索关系表,然后通过用户搜索框输入的keyword异步调用数据表中的相关 ...
- POJ 题目1204 Word Puzzles(AC自己主动机,多个方向查询)
Word Puzzles Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 10244 Accepted: 3864 S ...
- Calling a parent window function from an iframe
I want to call a parent window JavaScript function from an iframe. <script>function abc(){ ale ...
- docker启动centos容器后如何用putty连接
在前面的文章中,我提到过,win10 docker启动容器时,只有配置了宿主机和docker容器的端口映射,外部应用才能访问到容器中的服务,比如映射到Nginx的80端口.现在我将宿主机的某个端口映射 ...
- android NDK 使用(多个)静态库生成动态库
android NDK 使用(多个)静态库生成动态库. 1.编写Android.mk文件:如下两种方式都可以,用于NDK编译工具生成的两个.a文件来生成最终的libtwolib-second.so动态 ...