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 ...
随机推荐
- TCP/IP中你不得不知的十大秘密
这段时间 有一点心很浮躁,不过希望自己马上要矫正过来.好好学习编程!这段时间我想好好地研究一下TCP/IP协议和网络传输这块!加油 一.TCP/IP模型 TCP/IP协议模型(Transmission ...
- DotNetCore跨平台~linux上还原自主nuget包需要注意的问题
问题的产生的背景 由于我们使用了jenkins进行部署(jenkins~集群分发功能和职责处理),而对于.net core项目来说又是跨平台的,所以对它的项目拉取,包的还原,项目的编译和项目的发布都是 ...
- jdk版本查看,以及java -version 和JAVA_HOME不一致问题
一.jdk版本查看及位数查看 在cmd进入命令行窗口,输入java -version 可以查看安装的jdk版本,如图: 当有64-bit时代表是64位jdk,如果没有则默认是32位的. 二.java ...
- 零复制(zero copy)技术
html { font-family: sans-serif } body { margin: 0 } article,aside,details,figcaption,figure,footer,h ...
- java中集合的增删改操作及遍历总结
集合的增删改操作及遍历总结
- 使用java实现面向对象-File I/O
java.io.File类用于表示文件(目录) File类只用于表示文件(目录)的信息(名称.大小等),不能用于文件内容的访问 RandomAccessFile java提供的对文件内容的访问,既可以 ...
- PHP通过访客来路获取搜索关键词的方法
<?php class keyword{ public function getKeyword($referer){ if(strpos($referer,"http://www.ba ...
- 委托、事件、Observer观察者模式的使用解析二
一.设计模式-Observer观察者模式 Observer设计模式是为了定义对象间的一种一对多的依赖关系,以便于当一个对象的状态改变时,其他依赖于它的对象会被自动告知并更新.Observer模式是一种 ...
- Log4j按级别输出日志到不同文件配置分析 (转:projava)
关于LOG4J 按照级别输出日志,并按照级别输出到不同文件中的说法有很多, 网上贴的最多的log4j.properties的设置是这样的 log4j.rootLogger=info,stdout,in ...
- ASP.NET没有魔法——ASP.NET MVC 与数据库大集合
ASP.NET没有魔法——ASP.NET与数据库 ASP.NET没有魔法——ASP.NET MVC 与数据库之MySQL ASP.NET没有魔法——ASP.NET MVC 与数据库之ORM ASP.N ...