链接:

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;
}

最新文章

  1. [转]OAuth 2.0 - Authorization Code授权方式详解
  2. 【51Nod 1616】【算法马拉松 19B】最小集合
  3. 实际项目中的一个angularjs 应用
  4. [Android]ListView的Adapter.getView()方法中延迟加载图片的优化
  5. Visual Studio 2013编辑HTML文件无设计视图的解决方案
  6. (转)linux grep 正则表达式
  7. [原创]java WEB学习笔记70:Struts2 学习之路-- 输入验证,声明式验证,声明是验证原理
  8. Workflow Mailer Notifications设置
  9. JAVA面试基础
  10. quora 中有关angular与emberjs的精彩辩论
  11. Django开发网站(二)
  12. Jetty 8长连接上的又一个坑
  13. eclipse总是自动跳到ThreadPoolExecutor.java
  14. bootstrap js插件
  15. jQuery中的ready方法及实现按需加载css,js
  16. Solr 按照得分score跟指定字段相乘排序
  17. Jquery对raido的一些操作方法
  18. 微信支付——openid获取不到
  19. 利用“Java同包同名类执行顺序”取消Java 网站应用程序Licence验证
  20. 关于ORA-12505, TNS:listener does not currently know of SID given in connect descriptor报错问题解决办法

热门文章

  1. HTML布局之左右结构,左边固定右边跟据父元素自适应
  2. socket,获取html,webservice等,支持chunked,gzip,deflate
  3. 一小时搞明白自定义注解(Annotation)
  4. BZOJ 1196 [HNOI2006]公路修建问题:二分 + 贪心生成树check(类似kruskal)
  5. laravel基础课程---15、分页及验证码(lavarel分页效果如何实现)
  6. Log4Net的使用之winform
  7. mvc 让伪静态变得简单
  8. 数据结构与算法(5)-----&gt;二叉树
  9. POJ2887(块状链表)
  10. 响应式web设计,html5和css3实战(@author Ben Fraim)