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++ ...
随机推荐
- BZOJ1799 [Ahoi2009]self 同类分布[数位DP]
求出[a,b]中各位数字之和能整除原数的数的个数. 有困难的一道题.被迫看了题解:枚举每一个各位数字的和($<=162$),设计状态$f[len][sum][rest]$表示dp后面$len$位 ...
- uoj problem 12 猜数
题目大意 每次询问给出g,l,有\(a*b = g*l = n\),且\(a,b\)均为\(g\)的倍数.求\(a+b\)的最小值和\(a-b\)的最大值. 题解 因为\(a,b\)均为\(g\)的倍 ...
- 作为.NET程序员,您需要IronPython么?
.NET作为一个成熟的开发平台,为很多语言的发展提供了肥沃的土壤:历史相对久远的有Managed C++.C#.VB.NET.J#,正值壮年的则有IronPython.IronRuby,而老赵极力推崇 ...
- lua 函数调用 -- 闭包详解和C调用
转自:http://www.cnblogs.com/ringofthec/archive/2010/11/05/luaClosure.html 这里, 简单的记录一下lua中闭包的知识和C闭包调用 前 ...
- c++17 filesystem, regex 遍历目录
linux 遍历目录+文件(优化版本) c++17 FS 还是挺好用的, VS2017支持,但是linux g++7.3 还是不支持 filesystem #include<filesystem ...
- C#对SQL数据库操作类简介:Connection、Command、DataReader、DataSet、DataAdapter
在说C#操作数据库之前需要先说下ADO.NET.ADO.NET的名称起源于ADO(ActiveX Data Objects),是一个COM组件库,用于在以往的Microsoft技术中访问数据.之所以使 ...
- C++ 替换字符串内某个字符或子串
1. 问题描述 string s="abc"; string tmp="1"; 2.解决方案 // tmp 必须为字符串 // 第一个 1 表示 s 中的位置 ...
- Java enum(枚举)使用详解之二
enum 对象的常用方法介绍 int compareTo(E o) 比较此枚举与指定对象的顺序. Class<E> getDeclaringClass() ...
- Bluetooth Functions
The functions in this section are used for managing Bluetooth devices and services. Bluetooth is als ...
- BAT小米奇虎美团迅雷携程等等各大企业校招,笔试面试题。
类似在线测试的方式展示题目. 历年在线笔试试卷: 百度 http://www.nowcoder.com/paper/search?query=%E7%99%BE%E5%BA%A6 腾讯http:// ...