博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【BZOJ】1664: [Usaco2006 Open]County Fair Events 参加节日庆祝(线段树+dp)
阅读量:7246 次
发布时间:2019-06-29

本文共 2439 字,大约阅读时间需要 8 分钟。

和之前的那题一样啊。。

只不过权值变为了1.。

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

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

#include 
#include
#include
#include
#include
#include
#include
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
>1#define lson l, m, lc#define rson m+1, r, rcconst 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

 

 


 

 

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

转载地址:http://mknbm.baihongyu.com/

你可能感兴趣的文章
git 分支管理
查看>>
【高效程序员系列】目录
查看>>
JS中循环逻辑和判断逻辑的使用实例
查看>>
从零开始开发一个简易的类vue-cli构建工具
查看>>
中国工业软件成立联盟合力对外
查看>>
PAT 2-10. 海盗分赃(25)
查看>>
网络攻防_实验二+
查看>>
Quick-Cocos2d-x初学者游戏教程(十) ---------------- 添加游戏障碍物
查看>>
Maven环境下MyBatisGenerator 配置
查看>>
20180925-6 四则运算试题生成
查看>>
django 验证码实现
查看>>
HTML - 网页特殊字符大全(转)
查看>>
sift算法中翻译的第11页中比值问题
查看>>
Unity3D研究院编辑器之不实例化Prefab获取删除更新组件(十五)
查看>>
centos7搭建FTP服务器
查看>>
HDU-4033 Fruit Ninja 几何 二分搜索
查看>>
POJ-1057 FILE MAPPING 恶心模拟
查看>>
SpringMVC 之数据转换和国际化
查看>>
(Struts)ActionForm类及表单数据验证
查看>>
【php】phpExcel使用教程,如何导出excel表格
查看>>