CodeForces 597BRestaurant(饭店准备餐桌问题)
来源:互联网 发布:深圳淘宝化妆品销售 编辑:程序博客网 时间:2024/04/30 11:56
B. Restaurant
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
A restaurant receivednorders for the rental. Each rental order reserve the restaurant for acontinuous period of time, the i-thorder is characterized by two time values — the start timeliand the finish timeri(li ≤ ri).
Restaurant managementcan accept and reject orders. What is the maximal number of orders therestaurant can accept?
No two acceptedorders can intersect, i.e. they can't share even a moment of time. If one orderends in the moment other starts, they can't be accepted both.
Input
The first linecontains integer numbern (1 ≤ n ≤ 5·105)— number of orders. The following nlines contain integer valuesliandrieach (1 ≤ li ≤ ri ≤ 109).
Output
Print the maximal number of ordersthat can be accepted.
Examples
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
参考题意:
给你一组数据,表示客人的用餐时间,问你需要最少准备多少张桌子。
参考思路:
对结束的时间进行排序,然后判断。(参考《挑战程序设计竞赛》)
参考代码:
#include<stdio.h>#include<stdlib.h>#include<math.h>#include<string.h>#include<algorithm>#define MYDD 110300*5using namespace std;struct Q {int lai;int zou;} dd[MYDD];bool cmp_zou(Q x,Q y) {return x.zou<y.zou;}int main() {int n,ans,away;while(scanf("%d",&n)!=EOF) {for(int j=0; j<n; j++)scanf("%d%d",&dd[j].lai,&dd[j].zou);sort(dd,dd+n,cmp_zou);//for(int j=0; j<n; j++)//printf("******%d %d******\n",dd[j].lai,dd[j].zou);ans=0;away=0;for(int j=0; j<n; j++) {if(away<dd[j].lai) {away=dd[j].zou;//printf("****%d*****\n",away);ans++;}}printf("%d\n",ans);}return 0;}/*64 81 54 72 51 36 8*/
- CodeForces 597BRestaurant(饭店准备餐桌问题)
- 餐桌问题
- HUST 1584 摆放餐桌(计算几何)
- (cogs 613 火车站饭店)<树形DP>
- 五星大饭店完整剧情,五星大饭店(完整集数)在线观看
- 关于饭店手续一次性消毒餐具问题的看法
- 实用食品英语 (餐桌上用的)
- 餐桌文化
- 饭店点菜场景练习(日语对话练习)
- 五星大饭店续集剧情大放送(最新更新)
- 03饭店管理系统总结(附带代码及报告)
- 无穷饭店
- 村子-饭店
- 德辅道饭店
- 卢旺达饭店
- 饭店仿真
- 面试问题准备
- 机房准备问题小结
- CodeForces 612BHDD is Outdated Technology(磁盘顺道寻址问题)
- 利用MyEclipse自动创建PO类、hbm文件(映射文件)、DAO
- Android国内一线互联网公司内部面试题库
- 52. N-Queens II
- hdoj 1698 Just a Hook
- CodeForces 597BRestaurant(饭店准备餐桌问题)
- 从0开始的机器学习的学习
- 第三方支付之支付宝支付
- 7.13 编写一个程序,将两个字符串连接起来,不要用strcat函数。
- 改善java程序之java通用方法和准则
- ionic run android failed, error gradle line 64
- 项目管理过程组(5)与知识领域(10)
- Linux环境搭建
- js基础学习之--BOM基础知识总结