首页 技术 正文
技术 2022年11月8日
0 收藏 698 点赞 1,397 浏览 2718 个字

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

Silver

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,999
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,511
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,357
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,140
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848