http://www.lydsy.com/JudgeOnline/problem.php?id=1664

和之前的那题一样啊。。

只不过权值变为了1.。

同样用线段树维护区间,然后在区间范围内dp。

upd:(其实权值为1的可以直接贪心。。。。右端点来就行了。。。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; }
#define lc x<<1
#define rc x<<1|1
#define MID (l+r)>>1
#define lson l, m, lc
#define rson m+1, r, rc
const int N=10005;
int mx[N<<8], mxi, n;
struct dat { int a, b; }a[N];
bool cmp(const dat &a, const dat &b) { return a.a<b.a; }
void pushup(int x) { mx[x]=max(mx[lc], mx[rc]); }
void update(int l, int r, int x, int key, int p) {
if(l==r) {
mx[x]=key;
return;
}
int m=MID;
if(p<=m) update(lson, key, p); else update(rson, key, p);
pushup(x);
}
int query(int l, int r, int x, int L, int R) {
if(L<=l && r<=R) return mx[x];
int m=MID, ret=0;
if(L<=m) ret=query(lson, L, R); if(m<R) ret=max(ret, query(rson, L, R));
return ret;
} int main() {
read(n);
for1(i, 1, n) read(a[i].a), read(a[i].b), mxi=max(a[i].a+a[i].b, mxi);
sort(a+1, a+1+n, cmp);
int ans;
for1(i, 1, n) {
if(a[i].a<=1) ans=0; else ans=query(1, mxi, 1, 1, a[i].a-1);
update(1, mxi, 1, ans+1, a[i].a+a[i].b-1);
}
print(query(1, mxi, 1, 1, mxi));
return 0;
}

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

【BZOJ】1664: [Usaco2006 Open]County Fair Events 参加节日庆祝(线段树+dp)的更多相关文章

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

    先按时间排序( 开始结束都可以 ) , 然后 dp( i ) = max( dp( i ) , dp( j ) + 1 ) ( j < i && 节日 j 结束时间在节日 i 开 ...

  2. bzoj 1664: [Usaco2006 Open]County Fair Events 参加节日庆祝【dp+树状数组】

    把长度转成右端点,按右端点排升序,f[i]=max(f[j]&&r[j]<l[i]),因为r是有序的,所以可以直接二分出能转移的区间(1,w),然后用树状数组维护区间f的max, ...

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

    1664: [Usaco2006 Open]County Fair Events 参加节日庆祝 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 255  S ...

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

    Description Farmer John has returned to the County Fair so he can attend the special events (concert ...

  5. [Usaco2006 Open]County Fair Events 参加节日庆祝

    Description Farmer John has returned to the County Fair so he can attend the special events (concert ...

  6. 【动态规划】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 ...

  7. [BZOJ 1218] [HNOI2003] 激光炸弹 【n logn 做法 - 扫描线 + 线段树】

    题目链接:BZOJ - 1218 题目分析 可以覆盖一个边长为 R 的正方形,但是不能包括边界,所以等价于一个边长为 R - 1 的正方形. 坐标范围 <= 5000 ,直接 n^2 的二维前缀 ...

  8. [BZOJ 3207] 花神的嘲讽计划Ⅰ【Hash + 可持久化线段树】

    题目链接:BZOJ - 3207 题目分析 先使用Hash,把每个长度为 k 的序列转为一个整数,然后题目就转化为了询问某个区间内有没有整数 x . 这一步可以使用可持久化线段树来做,虽然感觉可以有更 ...

  9. BZOJ.3218.a + b Problem(最小割ISAP 可持久化线段树优化建图)

    BZOJ UOJ 首先不考虑奇怪方格的限制,就是类似最大权闭合子图一样建图. 对于奇怪方格的影响,显然可以建一条边\((i\to x,p_i)\),然后由\(x\)向\(1\sim i-1\)中权值在 ...

随机推荐

  1. android KK版本号收到短信后,点亮屏的操作

    alps/packages/apps/mms/src/comandroid\mms\transation\MessagingNotification.java private static void ...

  2. 算法笔记_026:折半查找(Java)

    目录 1 问题描述 2 解决方案 2.1 递归法 2.2 迭代法 1 问题描述 首先,了解一下何为折半查找?此处,借用<算法设计与分析基础>第三版上一段文字介绍: 2 解决方案 2.1 递 ...

  3. ant design pro (十四)advanced 使用 CLI 工具

    一.概述 原文地址:https://pro.ant.design/docs/cli-cn 为了更好以及高效的开发效率,我们提供了配套的 ant-design-pro-cli 工具. pro cli 提 ...

  4. ant design pro (四)新增页面

    一.概述 参看地址:https://pro.ant.design/docs/new-page-cn 这里的『页面』指配置了路由,能够通过链接直接访问的模块,要新建一个页面,通常只需要在脚手架的基础上进 ...

  5. 移动端项目中 @2x 图 和 @3x 图 的使用

    移动端开发过程中,因为手机的dpr(设备像素比不同),我们需要根据dpr来修改图标的大小: 1.通过mixin,动态修改图标的背景图片.通过@media (媒体查询),判断设备的dpr. @mixin ...

  6. Nginx如何保留真实IP和获取前端IP

    原理: squid,varnish以及nginx等,在做反向代理的时候,因为要代替客户端去访问服务器,所以,当请求包经过反向代理后,在代理服务器这里这个IP数据包的IP包头做了修改,最终后端web服务 ...

  7. 〖C语言〗C语言一个函数传递无限制多参数(不确定参数函数)的方法

    /* * ===================================================================================== * * Filen ...

  8. adb详解

    adb详解 分类: android开发工具相关 2012-10-24 18:27 2822人阅读 评论(0) 收藏 举报 ADB全称Android Debug Bridge,是android sdk里 ...

  9. 纯CSS实现蜂窝六边形的个性相册

    概述 纯CSS实现蜂窝六边形的个性相册 详细 代码下载:http://www.demodashi.com/demo/12804.html 此案例主要用到CSS3的 transform 和 transi ...

  10. 从0开始搭建symphony

    目标:在本地服务器中运行symphonyX 困难:=.= 基本全是困难…服务器重装了win/ubuntu/centos均不识别网卡,也是醉了. 1.通过Eclipse进行配置. 一开始以为需要单独下载 ...