TOJ 2867.Picking Problem(最大区间调度)
来源:互联网 发布:配置交换机端口类型 编辑:程序博客网 时间:2024/06/05 06:52
题目链接:http://acm.tju.edu.cn/toj/showp2762.html
Time Limit: 1.0 Seconds Memory Limit: 65536K
Total Runs: 1969 Accepted Runs: 831
On holiday, Kandy happens to come to a square. People there are playing different kinds of games. Each game has a start time and a lasting duration. Two or more games may carry on at the same time. Kandy likes the games so much that he wants to take apart in as many as possible games. Given the list of all the games, can you help him to calculate the maximum number of games that he can take.
Input
There are several test cases. The first line of each test case is a single integer N, which is the total number of the games (1 ≤ N ≤ 10000). It's followed by N lines, each line has two integers, S and D, and S is the start time of the ith game, and D is the game's duration (0 ≤ S ≤ 10000, 1 ≤ D ≤ 1000).The last case is followed by a single integer 0.
Output
For each case, output one line with a single integer M, which is the maximum number of games that Kandy can take.Sample Input
50 35 109 23 42 20
Sample Output
3
Hint: In the sample, the first game starts at 0, ends at 3, and the forth game starts at 3, ends at 7, and the third game starts at 9, ends at 11. So he can pick these three games.
Source: TJU Team Selection Contest 2007 (3)
题目大意:给定一系列活动的开始时间和结束时间,问最多能参加的活动数目
思路:// 本题属于最大区间调度问题,即数轴上有n个区间,选出最多的区间,使这些区间互相不重叠。算法:按右端点坐标排序,然后依次按后者的开始时间是否大于前者的结束时间(注意更新前者的下标)选择所有能选的区间。
#include <stdio.h>#include <algorithm>using namespace std;struct game{int s,e;};bool com(game a,game b){return a.e<b.e;}int main(){game games[10001];int n,dur;while(~scanf("%d",&n),n){for(int i=0;i<n;i++){scanf("%d%d",&games[i].s,&dur);games[i].e=games[i].s+dur;}sort(games,games+n,com);int m=0,sum=1;for(int i=1;i<n;i++)if(games[i].s>=games[m].e){sum++;m=i;}printf("%d\n",sum);}}
0 0
- TOJ 2867.Picking Problem(最大区间调度)
- toj 2867. Picking Problem
- 区间调度问题(最大利润作业调度问题)
- toj2867 Picking Problem
- 贪心区间调度 Greedy interval scheduling problem
- TOJ 10006 Josephus Problem
- TOJ A+B Problem
- TOJ 3761 Egg Problem
- TOJ 4112 Counting problem
- TOJ 2821.Grouping Problem
- TOJ 1753.Hamming Problem
- Toj 3777 Function Problem
- 区间调度问题(贪心)
- uvaLive 2387 - Gene Assembly 最大区间调度问题
- 区间调度
- TOJ 3777.Function Problem(三分基础题目)
- TOJ 4168 I-The brute force problem(数论)
- TOJ 4171 L-The math problem(水题)
- 坚持#第21天~学好专业知识!
- Faster RCNN 添加 ROIPoolingLayer 和SmoothL1LossLayer
- activity详解一
- hdfs的一些命令
- 几种常见模式识别算法整理和总结
- TOJ 2867.Picking Problem(最大区间调度)
- 杭电2002 2003/2001 2003
- break、continue、return的用法
- 第一次面试(厦门西联电子)
- Linux文件和目录的粘滞位的使用
- hbm配置文档
- 主元分析(PCA)理论分析及应用
- 数据结构之堆栈
- python3 爬取淘女郎照片