Testing Round #12 B
Description
A restaurant received n orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the i-th order is characterized by two time values — the start time li and the finish time ri (li ≤ ri).
Restaurant management can accept and reject orders. What is the maximal number of orders the restaurant can accept?
No two accepted orders can intersect, i.e. they can't share even a moment of time. If one order ends in the moment other starts, they can't be accepted both.
The first line contains integer number n (1 ≤ n ≤ 5·105) — number of orders. The following n lines contain integer values li and ri each (1 ≤ li ≤ ri ≤ 109).
Print the maximal number of orders that can be accepted.
2
7 11
4 7
1
5
1 2
2 3
3 4
4 5
5 6
3
6
4 8
1 5
4 7
2 5
1 3
6 8
2
贪心,求最多的不相交线段
#include<bits/stdc++.h>
using namespace std;
struct P
{
int s,e;
}He[5*100000];
bool cmd(P x,P y)
{
return x.e<y.e;
}
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>He[i].s>>He[i].e;
}
sort(He,He+n,cmd);
int sum=He[0].e;
int pos=1;
for(int i=0;i<n;i++)
{
if(He[i].s>sum)
{
sum=He[i].e;
pos++;
}
}
cout<<pos<<endl;
return 0;
}
Testing Round #12 B的更多相关文章
- Codeforces Testing Round #12 C. Subsequences 树状数组
C. Subsequences For the given sequence with n different elements find the number of increasing s ...
- Testing Round #12 A
A. Divisibility time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces Testing Round #12 C. Subsequences 树状数组维护DP
C. Subsequences Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- Codeforces Testing Round #12 B. Restaurant 贪心
B. Restaurant Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/problem ...
- Codeforces Testing Round #12 A. Divisibility 水题
A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- Testing Round #12 A,B,C 讨论,贪心,树状数组优化dp
题目链接:http://codeforces.com/contest/597 A. Divisibility time limit per test 1 second memory limit per ...
- Testing Round #12 C
Description For the given sequence with n different elements find the number of increasing subsequen ...
- “玲珑杯”ACM比赛 Round #12题解&源码
我能说我比较傻么!就只能做一道签到题,没办法,我就先写下A题的题解&源码吧,日后补上剩余题的题解&源码吧! A ...
- Codeforces Beta Round #12 (Div 2 Only)
Codeforces Beta Round #12 (Div 2 Only) http://codeforces.com/contest/12 A 水题 #include<bits/stdc++ ...
随机推荐
- POJ2406Power Strings (最小循环节)(KMP||后缀数组)
Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc&quo ...
- ACM学习历程—HDU5592 ZYB's Premutation(逆序数 && 树状数组 && 二分)(BestCoder Round #65 1003)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5592 题目大意就是给了每个[1, i]区间逆序对的个数,要求复原原序列. 比赛的时候2B了一发. 首先 ...
- HUD1455:Sticks
Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- 【转】 Pro Android学习笔记(三七):Fragment(2):基础小例子
目录(?)[-] 小例子运行效果 Pre-step一点准备 Step 1Activity的布局 小例子运行效果 这是一个书名和书简介的例子.运行如下图.Activity由左右两个Fragment组成, ...
- 一 Akka学习 - actor
(引用 http://shiyanjun.cn/archives/1168.html) 一: 什么是Akka? Akka是JAVA虚拟机JVM平台上构建高并发.分布式和容错应用的工具包和运行时,是一个 ...
- 关于startactivity初始化activity的过程以及activity和window以及view的关系
activity 构造一个实现了window的phonewindow,获得viewroot,然后往里面加入view 当发生事件的时候,如KEYDOWN,windowmanagerservice就接受到 ...
- Angular11 模板表单、响应式表单(自定义验证器)、HTTP、表单元素双向绑定
1 模板表单 模型通过指令隐式创建 技巧01:需要在模块级别引入 FormsModule ,通常在共享模块中引入再导出,然后在需要用到 FormsModule 的模块中导入共享模块就可以啦 impor ...
- 在PCL中如何实现点云压缩(2)
博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=125 压缩配置文件: 压缩配置文件为PCL点云编码器定义了参数集.并针对压缩 ...
- PCLVisualizer可视化类(5)
博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=171 自定义交互 多数情况下,默认的鼠标和键盘交互设置不能满足用户的需求,用 ...
- unreal3对象管理模块分析
凡是稍微大一点的引擎框架,必然都要自己搞一套对象管理机制,如mfc.qt.glib等等,unreal自然也不例外. 究其原因,还是c++这种静态语言天生的不足,缺乏运行时类型操作功能,对于复杂庞大的逻 ...