County Fair Events
先按照结束时间进行排序,取第一个节日的结束时间作为当前时间,然后从第二个节日开始搜索,如果下一个节日的开始时间大于当前的时间,那么就参加这个节日,并更新当前时间
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e4+5;
struct node {
int be, ed; // 开始时间和结束时间
}nds[maxn];
bool cmp(node x, node y) {
return x.ed < y.ed;
}
int main() {
int n; cin >> n;
for (int i = 1; i <= n; ++i) {
int t, l; cin >> t >> l;
nds[i].be = t, nds[i].ed = t+l-1;
}
// 按照节日的结束时间从小到大进行排序
sort(nds+1,nds+1+n,cmp);
// 取第一个节日的结束时间作为当前的时间,答案赋值为1
int now_time = nds[1].ed, ans = 1;
for (int i = 2; i <= n; ++i) {
// 如果下一个节日的开始时间大于当前的时间,那么参加这个节日
// 因为是按照结束时间进行排序的,所以参加这个节日肯定最优
if (nds[i].be > now_time) {
// 答案加一
ans++;
// 更新当前时间
now_time = nds[i].ed;
}
}
cout << ans << endl;
return 0;
}
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. ...
- [Usaco2006 Open]County Fair Events 参加节日庆祝
Description Farmer John has returned to the County Fair so he can attend the special events (concert ...
- 【动态规划】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, ...
- usaco silver
大神们都在刷usaco,我也来水一水 1606: [Usaco2008 Dec]Hay For Sale 购买干草 裸背包 1607: [Usaco2008 Dec]Patting Heads 轻 ...
- BZOJ-USACO被虐记
bzoj上的usaco题目还是很好的(我被虐的很惨. 有必要总结整理一下. 1592: [Usaco2008 Feb]Making the Grade 路面修整 一开始没有想到离散化.然后离散化之后就 ...
随机推荐
- java中Future的使用
文章目录 创建Future 从Future获取结果 取消Future 多线程环境中运行 java中Future的使用 Future是java 1.5引入的一个interface,可以方便的用于异步结果 ...
- 使用VSCode连接到IBM Cloud区块链网络
文章目录 从IBM Cloud控制面板导出连接信息 在VSCode中创建gateway和wallet 在VSCode中提交transaction 上篇文章我们讲到怎么在IBM Cloud搭建区块链环境 ...
- Linux命令(4):touch
功能说明: touch命令参数可创建新文件以及更改文档或目录的日期时间,包括存取时间和更改时间. 命令格式: touch [选项]... 文件... 命令参数: -a 或--time=atime或 ...
- 《WCF技术内幕》翻译3:第1部分_第1章_蓝月亮:普遍需求和普遍概念
第一部分:WCF介绍 章节目录: 第1章:蓝月亮 第2章:面向服务 第3章:消息交换模式.拓扑和编排 第4章:WCF 101 第1章:蓝月亮 商业和市场对软件系统新 ...
- 02-线性结构4 Pop Sequence
02-线性结构4 Pop Sequence (25分) 时间限制:400ms 内存限制:64MB 代码长度限制:16kB 判题程序:系统默认 作者:陈越 单位:浙江大学 https://pta.p ...
- Eclipse 全部快捷一览表(具TM全)
1. 编辑快捷键 编辑快捷键 介绍 psvm + Tab 生成main方法 sout + tab 生成输出语句 Ctrl+X / Ctrl + Y 删除一行 Ctrl+D 复制一行 Ctrl+/ 或 ...
- POJ 3267为什么优先队列超时,DP就能过,难过
The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11846 Accepted: 5693 Desc ...
- 图论--网络流--费用流--POJ 2156 Minimum Cost
Description Dearboy, a goods victualer, now comes to a big problem, and he needs your help. In his s ...
- CodeForces - 1245A Good ol' Numbers Coloring (思维)
Codeforces Round #597 (Div. 2 Consider the set of all nonnegative integers: 0,1,2,-. Given two integ ...
- CF #632 (Div. 2) 对应题号CF1333
1333A Little Artem 在一个\(n\)行\(m\)列的格子上染色,每个格子能染黑白两种 构造一种方案,使得四个方向有至少一个白色格子的黑色格子的数量,比四个方向有至少一个黑色格子的白色 ...