牛客假日团队赛2 G.CountyFairEvents
链接:
https://ac.nowcoder.com/acm/contest/924/G
题意:
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.
思路:
将持续时间改变成结束时间,然后直接按照结束时间贪心即可。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
int n, m, k, t;
struct Node
{
int l, r;
bool operator < (const Node & that) const
{
if (this->r != that.r)
return this->r < that.r;
return this->l > that.l;
}
}node[MAXN];
int main()
{
cin >> n;
for (int i = 1;i <= n;i++)
{
cin >> node[i].l >> node[i].r;
node[i].r += node[i].l;
}
sort(node+1, node+1+n);
int last = 0, res = 0;
for (int i = 1;i <= n;i++)
{
if (node[i].l >= last)
res++, last = node[i].r;
}
cout << res << endl;
return 0;
}
牛客假日团队赛2 G.CountyFairEvents的更多相关文章
- 牛客假日团队赛1 G.Superbull
链接: https://ac.nowcoder.com/acm/contest/918/G 题意: Bessie and her friends are playing hoofball in the ...
- 牛客假日团队赛10 L 乘积最大 (dp,大数)
链接:https://ac.nowcoder.com/acm/contest/1072/L?&headNav=acm&headNav=acm 来源:牛客网 乘积最大 时间限制:C/C+ ...
- P5200 [USACO19JAN]Sleepy Cow Sorting 牛客假日团队赛6 D 迷路的牛 (贪心)
链接:https://ac.nowcoder.com/acm/contest/993/E 来源:牛客网 对牛排序 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言 ...
- 牛客假日团队赛6 D 迷路的牛 (思维)
链接:https://ac.nowcoder.com/acm/contest/993/D 来源:牛客网 迷路的牛 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言 ...
- 牛客假日团队赛5J 护城河 bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 (凸包的周长)
链接:https://ac.nowcoder.com/acm/contest/984/J 来源:牛客网 护城河 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6 ...
- 牛客假日团队赛5 K 金币馅饼 (DP 基础题)
链接:https://ac.nowcoder.com/acm/contest/984/K 来源:牛客网 金币馅饼 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言 ...
- 牛客假日团队赛5 L Catch That Cow HDU 2717 (BFS)
链接:https://ac.nowcoder.com/acm/contest/984/L 来源:牛客网 Catch That Cow 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 3 ...
- 牛客假日团队赛5 F 随机数 BZOJ 1662: [Usaco2006 Nov]Round Numbers 圆环数 (dfs记忆化搜索的数位DP)
链接:https://ac.nowcoder.com/acm/contest/984/F 来源:牛客网 随机数 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6 ...
- 洛谷 P2866 [USACO06NOV]糟糕的一天Bad Hair Day 牛客假日团队赛5 A (单调栈)
链接:https://ac.nowcoder.com/acm/contest/984/A 来源:牛客网 题目描述 Some of Farmer John's N cows (1 ≤ N ≤ 80,00 ...
随机推荐
- Ubuntu 更新/安装nodejs
nvm nvm是一个开源的Node版本管理器,通过简单的bash脚本来管理.切换多个Node.js版本.和nvm提供类似功能的还有tj写的n,它们的功能大同小异,整体来说nvm要稍强大一下.值得注意的 ...
- axios无法在ie9,10,11环境下运行的问题解决
npm install es6-promise --save-dev import promise from 'es6-promise'; promise.polyfill();
- BZOJ 1370 [Baltic2003]Gang团伙:并查集【虚点】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1370 题意: 在某城市里住着n个人,任何两个认识的人不是朋友就是敌人,而且满足: (1)我 ...
- BZOJ 1191 [HNOI2006]超级英雄Hero:二分图匹配 匈牙利算法
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1191 题意: 有m道题,每答对一题才能接着回答下一个问题. 你一道题都不会,但是你有n个“ ...
- 15 个最佳的 jQuery 布局插件【转】
英文原文:15 Best jQuery Grid Plugins for Developers 现如今,网站开发设计的需求会要求自动适应所有移动设备,即响应式网站: 在开发网站时必须考虑对平板设备融合 ...
- 时间序列数据库——索引用ES、聚合分析时加载数据用什么?docvalues的列存储貌似更优优势一些
加载 如何利用索引和主存储,是一种两难的选择. 选择不使用索引,只使用主存储:除非查询的字段就是主存储的排序字段,否则就需要顺序扫描整个主存储. 选择使用索引,然后用找到的row id去主存储加载数据 ...
- smack api 转载未测试
===============================================================主动发送信息给某个用户-------------------------- ...
- L84
Hospital Noise May Disrupt Patient Improvement Many who need restorative rest the most might not be ...
- HDU6118:度度熊的交易计划(入门级最小费用可行流)
度度熊参与了喵哈哈村的商业大会,但是这次商业大会遇到了一个难题: 喵哈哈村以及周围的村庄可以看做是一共由n个片区,m条公路组成的地区. 由于生产能力的区别,第i个片区能够花费a[i]元生产1个商品,但 ...
- BZOJ-3626:LCA(离线+树链剖分)
Description 给出一个n个节点的有根树(编号为0到n-1,根节点为0).一个点的深度定义为这个节点到根的距离+1.设dep[i]表示点i的深度,LCA(i,j)表示i与j的最近公共祖先.有q ...