Restaurant
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.
Input
The first line contains integer number n (1 ≤ n ≤ 5·105) — number of orders. The following n lines contain integer values li and rieach (1 ≤ li ≤ ri ≤ 109).
Output
Print the maximal number of orders that can be accepted.
Sample Input
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
/*
题意:给你餐厅n组客人就餐时间(起始时间,终止时间)如果时间有重叠的话,那么两组客人不能同时用餐,问餐厅最多接纳多少组客人 初步思路:按照终止时间排序,然后贪心 */
#include <bits/stdc++.h>
using namespace std;
struct node{
int Frist,End;
bool operator <(const node &other) const{
return End<other.End;
}
}fr[];
int n;
int res=;
int last=;
void init(){
res=;
last=;
}
int main(){
// freopen("in.txt","r",stdin);
while(scanf("%d",&n)!=EOF){
init();
for(int i=;i<n;i++){
scanf("%d%d",&fr[i].Frist,&fr[i].End);
}
sort(fr,fr+n);
for(int i=;i<n;i++){
if(fr[i].Frist>last){
res++;
last=fr[i].End;
}
}
printf("%d\n",res);
}
return ;
}
Restaurant的更多相关文章
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- Flo's Restaurant[HDU1103]
Flo's Restaurant Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Codeforces Testing Round #12 B. Restaurant 贪心
B. Restaurant Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/problem ...
- HDU-2368 Alfredo's Pizza Restaurant
http://acm.hdu.edu.cn/status.php Alfredo's Pizza Restaurant Time Limit: 1000/1000 MS (Java/Others) ...
- hdoj 4883 TIANKENG’s restaurant【贪心区间覆盖】
TIANKENG’s restaurant Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/O ...
- hdu2368Alfredo's Pizza Restaurant
Problem Description Traditionally after the Local Contest, judges and contestants go to their favour ...
- HDOJ 4883 TIANKENG’s restaurant
称号: TIANKENG's restaurant Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Ja ...
- 九校联考_24OI——餐馆restaurant
凉心模拟D1T1--最简单的一道题 TAT 餐馆(restaurant) 题目背景 铜企鹅是企鹅餐馆的老板,他正在计划如何使得自己本年度收益增加. 题目描述 共有n 种食材,一份食材i 需要花ti 小 ...
- Codeforces828 A. Restaurant Tables
A. Restaurant Tables time limit per test 1 second memory limit per test 256 megabytes input standard ...
随机推荐
- Linux 更改ssh 端口
部署了一个测试服务器之后,在查看linux日志的时候,发现莫名的IP一直在访问服务器,感觉像是某种恶意扫描,来攻击服务器的.因此更改ssh端口. 输入: vim /etc/ssh/sshd_confi ...
- 记录一次无聊的(经历了Nodejs -> Shell -> C)的探索问题过程
提出问题 在运行项目的服务器的git是1.8.3.1版本的时候,pm2 deploy 项目,服务器fetch不到最新的一次commit. 对于这个问题,在pm2的github也有issues讨论.然后 ...
- call()和apply()的作用
call( )和apply( )都是为了改变某个函数运行时的上下文而存在的.换句话说是改变函数体内部this的指向 他们的区别就是call()方法接受的是若干个参数的列表,而apply()方法接受的是 ...
- Markdown 编写规范
说明及目的 作为一个在博客园混迹了俩三年的人,一直在这里看别人的博客,现在准备开始写自己的博客,目的呢,就是一下几点吧: 项目过程中的历史经验教训积累记载,吃一堑长一智,不想在同一个坑掉进去好几次 学 ...
- 用postal.js在AngularJS中实现订阅发布消息
点击查看AngularJS系列目录 用postal.js在AngularJS中实现event bus 用postal.js在AngularJS中实现event bus 理想状态下,在一个Angular ...
- Xcode 上传代码到GitHub
几乎所有iOS程序员都上过GitHub寻找开源类库,的确,GitHub上有大量优秀的开源类库供大家学习.但是如何在Xcode中上传代码至GitHub呢? (开始之前先安装git,具体方法这里讲的很清楚 ...
- Java虚拟机-运行时数据区域
Java虚拟机管理的内存包括如图所示的运行时数据区域: 下面分别进行介绍: 1)程序计数器(Program Counter Register) 占用的内存空间比较小,主要作用就是标识当前线程执行的字节 ...
- JAVA设计模式总结之23种设计模式
上一篇总结了设计模式的六大原则<JAVA设计模式总结之六大设计原则>,这一篇,正式进入到介绍23种设计模式的归纳总结. 一.什么是设计模式 ...
- spring框架总结(01)
1.spring是什么? sprint其实就是一个开源框架,是于2003年兴起的一个轻量级的java开发框架,是有Road Johnson创建的,简单的来说spring是一个分层的JavaSE/EE( ...
- R语言基础语法
学习一门新的语言,率先学习输出hello world.我们就从这里开始学习. 首先打开RStudio这个IDE,然后在左边输入: > mystr <- "hello world& ...