Restaurant

Time Limit:4000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status

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

Input
2
7 11
4 7
Output
1
Input
5
1 2
2 3
3 4
4 5
5 6
Output
3
Input
6
4 8
1 5
4 7
2 5
1 3
6 8
Output
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的更多相关文章

  1. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  2. Flo's Restaurant[HDU1103]

    Flo's Restaurant Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. Codeforces Testing Round #12 B. Restaurant 贪心

    B. Restaurant Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/problem ...

  4. HDU-2368 Alfredo's Pizza Restaurant

    http://acm.hdu.edu.cn/status.php Alfredo's Pizza Restaurant Time Limit: 1000/1000 MS (Java/Others)   ...

  5. hdoj 4883 TIANKENG’s restaurant【贪心区间覆盖】

    TIANKENG’s restaurant Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/O ...

  6. hdu2368Alfredo's Pizza Restaurant

    Problem Description Traditionally after the Local Contest, judges and contestants go to their favour ...

  7. HDOJ 4883 TIANKENG’s restaurant

    称号: TIANKENG's restaurant Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Ja ...

  8. 九校联考_24OI——餐馆restaurant

    凉心模拟D1T1--最简单的一道题 TAT 餐馆(restaurant) 题目背景 铜企鹅是企鹅餐馆的老板,他正在计划如何使得自己本年度收益增加. 题目描述 共有n 种食材,一份食材i 需要花ti 小 ...

  9. Codeforces828 A. Restaurant Tables

    A. Restaurant Tables time limit per test 1 second memory limit per test 256 megabytes input standard ...

随机推荐

  1. TCP/IP中你不得不知的十大秘密

    这段时间 有一点心很浮躁,不过希望自己马上要矫正过来.好好学习编程!这段时间我想好好地研究一下TCP/IP协议和网络传输这块!加油 一.TCP/IP模型 TCP/IP协议模型(Transmission ...

  2. DotNetCore跨平台~linux上还原自主nuget包需要注意的问题

    问题的产生的背景 由于我们使用了jenkins进行部署(jenkins~集群分发功能和职责处理),而对于.net core项目来说又是跨平台的,所以对它的项目拉取,包的还原,项目的编译和项目的发布都是 ...

  3. jdk版本查看,以及java -version 和JAVA_HOME不一致问题

    一.jdk版本查看及位数查看 在cmd进入命令行窗口,输入java -version 可以查看安装的jdk版本,如图: 当有64-bit时代表是64位jdk,如果没有则默认是32位的. 二.java ...

  4. 零复制(zero copy)技术

    html { font-family: sans-serif } body { margin: 0 } article,aside,details,figcaption,figure,footer,h ...

  5. java中集合的增删改操作及遍历总结

      集合的增删改操作及遍历总结

  6. 使用java实现面向对象-File I/O

    java.io.File类用于表示文件(目录) File类只用于表示文件(目录)的信息(名称.大小等),不能用于文件内容的访问 RandomAccessFile java提供的对文件内容的访问,既可以 ...

  7. PHP通过访客来路获取搜索关键词的方法

    <?php class keyword{ public function getKeyword($referer){ if(strpos($referer,"http://www.ba ...

  8. 委托、事件、Observer观察者模式的使用解析二

    一.设计模式-Observer观察者模式 Observer设计模式是为了定义对象间的一种一对多的依赖关系,以便于当一个对象的状态改变时,其他依赖于它的对象会被自动告知并更新.Observer模式是一种 ...

  9. Log4j按级别输出日志到不同文件配置分析 (转:projava)

    关于LOG4J 按照级别输出日志,并按照级别输出到不同文件中的说法有很多, 网上贴的最多的log4j.properties的设置是这样的 log4j.rootLogger=info,stdout,in ...

  10. ASP.NET没有魔法——ASP.NET MVC 与数据库大集合

    ASP.NET没有魔法——ASP.NET与数据库 ASP.NET没有魔法——ASP.NET MVC 与数据库之MySQL ASP.NET没有魔法——ASP.NET MVC 与数据库之ORM ASP.N ...