链接:

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. 牛客假日团队赛1 G.Superbull

    链接: https://ac.nowcoder.com/acm/contest/918/G 题意: Bessie and her friends are playing hoofball in the ...

  2. 牛客假日团队赛10 L 乘积最大 (dp,大数)

    链接:https://ac.nowcoder.com/acm/contest/1072/L?&headNav=acm&headNav=acm 来源:牛客网 乘积最大 时间限制:C/C+ ...

  3. P5200 [USACO19JAN]Sleepy Cow Sorting 牛客假日团队赛6 D 迷路的牛 (贪心)

    链接:https://ac.nowcoder.com/acm/contest/993/E 来源:牛客网 对牛排序 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言 ...

  4. 牛客假日团队赛6 D 迷路的牛 (思维)

    链接:https://ac.nowcoder.com/acm/contest/993/D 来源:牛客网 迷路的牛 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言 ...

  5. 牛客假日团队赛5J 护城河 bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 (凸包的周长)

    链接:https://ac.nowcoder.com/acm/contest/984/J 来源:牛客网 护城河 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6 ...

  6. 牛客假日团队赛5 K 金币馅饼 (DP 基础题)

    链接:https://ac.nowcoder.com/acm/contest/984/K 来源:牛客网 金币馅饼 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言 ...

  7. 牛客假日团队赛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 ...

  8. 牛客假日团队赛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 ...

  9. 洛谷 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 ...

随机推荐

  1. javascript类的简单定义

    在面向对象编程中,类(class)是对象(object)的模板,定义了同一组对象(又称"实例")共有的属性和方法. Javascript语言不支持"类",但是可 ...

  2. HTML5实现中国象棋游戏(无人能敌)

    1. [代码][JavaScript]代码    var AI = AI||{}; AI.historyTable =   {};     //历史表  //人工智能初始化AI.init = func ...

  3. IntelliJ IDEA 的 project 和 module 区别与关系

    在IDEA 创建一个project,目录结构是这样的:在project下创建一个module之后目录结构是这样的: 简单的概括如下: IntelliJ系中的 Project  相当于Eclipse系中 ...

  4. C# winform控件之PictureBox详解

    PictureBox表示用于显示图像的 Windows 图片框控件https://msdn.microsoft.com/zh-cn/library/system.windows.forms.pictu ...

  5. phpstorm 2016.3.2 的最新破解方法(截止2017-2-20)

    最新更新 ,http://idea.imsxm.com 这个地址是亲测可用的,针对最新的phpstorm 2016.3.2的版本.使用方式和下面一致,选择license server.然后复制http ...

  6. Katalon Recorder 自动录制 Selenium 爬虫脚本

    相信很多小伙伴都用过 Selenium 来完成爬虫工作,今天就给大家带来一个神器,可以录制你的浏览器动作,然后直接生成 Selenium 脚本,是不是心动了? 1 Selenium 简介 Seleni ...

  7. html制作细线表格

    关于这个细线表格的制作方法,百度一下可能就会有答案告诉你设置这几个值:给table设置border="0" cellspacing="1" bgcolor=&q ...

  8. plsql developer点滴

    PLSql中查看编译错误的具体内容: 1. 打开Command Windows show errors procedure procedure_name 

  9. C# 对象间的 深拷贝 实现

        以下的这个类实现了 2个含有部分字段名字相同 的对象的 赋值拷贝. public class ShallowCopyHelper     {         public static voi ...

  10. snmp++开发实例一

    1.官网下载 snmp开发,首先需要机器已经安装了snmp服务,这方面的资料网上比较完备,安装的时候注意每少一个文件,网上都可以下载到,这样可以自己形成一个包,供以后使用.只要最后snmp的服务开启就 ...