bzoj1664:参加节日庆祝

1664: [Usaco2006 Open]County Fair Events 参加节日庆祝

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 286  Solved: 207
[Submit][Status][Discuss]

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

INPUT DETAILS:

Graphic picture of the schedule:
11111111112
12345678901234567890---------这个是时间轴.
--------------------
111111 2222223333344
55555555 777777 666

这个图中1代表第一个节日从1开始,持续6个时间,直到6.

Sample Output

4

OUTPUT DETAILS:

FJ can do no better than to attend events 1, 2, 3, and 4.

HINT

Source

Silver

就是先排个序然后就是递推一下吧,好像白书里面有贪心的算法但是翻了很久就是翻不到。。

----------------------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<stack>
using namespace std;
const int nmax=10005;
int f[nmax];
struct edge{
 int l,r;
 bool operator<(const edge&rhs) const {
   return l<rhs.l||l==rhs.l&&r<rhs.r;}
};
edge a[nmax];
int main(){
 int n;
 scanf("%d",&n);
    for(int i=1,o;i<=n;i++){
     scanf("%d%d",&a[i].l,&o);
     a[i].r=a[i].l+o-1;
    }
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++){
     f[i]=1;
     for(int j=1;j<i;j++){
      if(a[i].l>a[j].r)
       f[i]=max(f[i],f[j]+1);
     }
    }
    printf("%d\n",f[n]);
    return 0;
}

-------------------------------------------------------------------------------

时间: 2025-01-06 03:03:19

bzoj1664:参加节日庆祝的相关文章

bzoj1664[Usaco2006 Open]County Fair Events 参加节日庆祝*

bzoj1664[Usaco2006 Open]County Fair Events 参加节日庆祝 题意: 有N个节日,每个节日有个开始时间,及持续时间.牛想尽可能多的参加节日,问最多可以参加多少.注意牛的转移速度是极快的,不花时间,且节日必须完整参加.N≤10000,开始时刻和持续时间≤100000. 题解: dp.设f[i]表示i时刻到最后时刻最多可以参加多少节日.则f[i]=max(f[i+1],f[range[j].r+1],j为时刻i开始的节日). 代码: 1 #include <cs

BZOJ 1664: [Usaco2006 Open]County Fair Events 参加节日庆祝( dp )

先按时间排序( 开始结束都可以 ) , 然后 dp( i ) = max( dp( i ) , dp( j ) + 1 ) ( j < i && 节日 j 结束时间在节日 i 开始时间之前 ) answer = max( dp( i ) ) ( 1 <= i <= n ) -------------------------------------------------------------------------------- #include<cstdio&g

[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 h

大神刷题表

9月27日 后缀数组:[wikioi3160]最长公共子串 dp:NOIP2001统计单词个数 后缀自动机:[spoj1812]Longest Common Substring II [wikioi3160]最长公共子串 [spoj7258]Lexicographical Substring Search 扫描线+set:[poj2932]Coneology 扫描线+set+树上删边游戏:[FJOI2013]圆形游戏 结论:[bzoj3706][FJ2014集训]反色刷 最小环:[poj1734

小结:线段树 &amp; 主席树

概要: 就是用来维护区间信息,然后各种秀智商游戏. 应用: 优化dp.主席树等. 技巧及注意: size值的活用:主席树就是这样来的.支持区间加减,例题和模板:主席树,[BZOJ]1146: [CTSC2008]网络管理Network(树链剖分+线段树套平衡树+二分 / dfs序+树状数组+主席树),[BZOJ]1901: Zju2112 Dynamic Rankings(区间第k小+树状数组套可持久化线段树(主席树)) 01(就是更新和不更新等这种对立操作)情况:我们就要在各个更新的操作中明白

小结:动态规划

概要: 状态.转移:最优子结构.无后效性. 技巧及注意: dp就是纯经验+智商题 在dp方程写出来后,一定要考虑边界!不要以为转移对了就行了! 滚动数组的话一定要考虑好顺序! 下标有时候可以灵活使用!比如mod意义下的dp,倍数什么.可到达性等题目都可以这样做. 如果是线性序列的max{f[k]},k<i这种可以用线段树或bit维护成log 注意“前i”和“第i”的区别(特别对于答案更新),有时换一种就能解答出问题. 在状态加限制条件,如单调.地址等. 用下标来维护下标这个答案是否可达. 博弈论

bzoj 1664 (贪心)

[Usaco2006 Open]County Fair Events 参加节日庆祝 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 487  Solved: 344[Submit][Status][Discuss] Description Farmer John has returned to the County Fair so he can attend the special events (concerts, rodeos, cooking s

表示欢迎大陆老兵来台参加活动

今年将举办一系列活动庆祝抗战胜利70周年,包括7月4日在新竹举办的战力展示.据<联合晚报>报道,罗绍和22日称,依据“内政部大陆人民来台从事观光活动许可办法”第15条规定,大陆人民来台行程排除“军事国防”地区等项,此外依据“国军开放营区入营人员身份查验作业要领”,明确规定入营对象是“中华民国国民”.罗绍和说,“国防部”欢迎居住在大陆的抗战老兵来台参加相关庆祝活动,但不得进入军事营区.也 http://baozoumanhua.com/users/15673260/talkingshttp://

看留学生如何过五一

[导读]五一又称五一国际劳动节.国际示威游行日(International Workers Day或者May Day),是世界上80多个国家的全国性节日.定在每年的五月一日.它是全世界劳动人民共同拥有的节日.1889年7月,        五一又称"五一国际劳动节"."国际示威游行日"(International Workers' Day或者May Day),是世界上80多个国家的全国性节日.定在每年的五月一日.它是全世界劳动人民共同拥有的节日.1889年7月,由恩