Restaurant (背包问题)
来源:互联网 发布:网易镜像站下载linux 编辑:程序博客网 时间:2024/06/14 07:17
点击题目打开链接
Restaurant
A restaurant received n orders for the rental. Each rental order reserve the restaurant for a continuous period of time, thei-th order is characterized by two time values — the start timeli and the finish timeri (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 followingn lines contain integer values li and ri each (1 ≤ li ≤ ri ≤ 109).
Print the maximal number of orders that can be accepted.
27 114 7
1
51 22 33 44 55 6
3
64 81 54 72 51 36 8
2
下面是我的代码:
#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>#include<cstdlib>#include<iostream>using namespace std;struct P{int star;int endd;}num[900000];bool cmp(P a,P b){return a.endd<b.endd;}int main(){int n,k,p;while(scanf("%d",&n)!=EOF){k=1;for(int i=0;i<n;i++){scanf("%d%d",&num[i].star,&num[i].endd);}sort(num,num+n,cmp);p=num[0].endd;for(int i=1;i<n;i++){if(num[i].star>p){k++;p=num[i].endd;}}printf("%d\n",k);}return 0;}
- Restaurant (背包问题)
- Restaurant (贪心)
- Restaurant
- Restaurant
- Restaurant
- 背包问题(分组背包)
- 背包问题(01背包,完全背包,多重背包)
- 背包问题(01背包,完全背包,多重背包)
- 背包(01背包、完全背包、多重背包)问题总结
- 背包问题(01背包,完全背包,多重背包)
- 背包问题(01背包 + 完全背包 + 多重背包)
- 背包问题(01背包,完全背包,多重背包)
- 背包问题模板(01背包,完全背包,多重背包)
- 经典背包问题----(01背包、完全背包、多重背包)
- LintCode-背包问题(01背包问题)
- UVA 1468 - Restaurant(推理)
- uva 1468 - Restaurant(贪心)
- TIANKENG’s restaurant(贪心)
- 存储过程
- arm linux 安装 ettercap
- hardway learning python 0730
- java系统学习(1、基础知识了解)
- windows下搭建nexus环境
- Restaurant (背包问题)
- 观建军90周年阅兵之感悟
- 递归与迭代
- 文件均分到目录
- Android客户端之“微服私访”App的系统学习(五)使用Picasso实现轮播图以及使用自定义View实现个人中心页面
- 哈夫曼算法(huffman algorithm C)
- Linux及 Linux Shell简介
- Ado/Ado.net与Asp/Asp.net关系
- Hook匹配过程----之二