toj2867 Picking Problem
题目链接:http://acm.tju.edu.cn/toj/showp.php?pid=2867
题目大意:给定一系列活动的开始时间和结束时间,问最多能参加的活动数目
思路:// 本题属于最大区间调度问题,即数轴上有n个区间,选出最多的区间,使这些区间互相不重叠。算法:按右端点坐标排序,然后依次按后者的开始时间是否大于前者的结束时间(注意更新前者的下标)选择所有能选的区间。
代码:
// 本题属于最大区间调度问题,即数轴上有n个区间,选出最多的区间,使这些区间互相不重叠。
// 算法:按右端点坐标排序,然后依次按后者的开始时间是否大于前者的结束时间(注意更新前者的下标)选择所有能选的区间。
#include<iostream>
#include<algorithm>
using namespace std;
struct node{
int s,e;
}activity[10000];
bool cmp(node a,node b)
{
return a.e<b.e; //按结束时间排序
}
int main()
{
int n,d,st,i,ct,m;
while(cin>>n&&n)
{
ct = 1; //最多能参加的活动数 初始化为1!!
for(i=0;i<n;i++)
{
cin>>st>>d;
activity[i].s = st;
activity[i].e = st+d;
}
sort(activity,activity+n,cmp);
m=0;
for(i=1;i<n;i++)
{
if(activity[i].s>=activity[m].e)
{
ct++; //如果后者的开始时间大于前者的结束时间,表明没有重合,能参加的活动数目加1
m=i; //后者和前者比,记着更新
}
}
cout<< ct<<endl;
}
return 0;
}
toj2867 Picking Problem的更多相关文章
- VTK拾取网格模型上的可见点
消隐与Z-Buffer 使用缓冲器记录物体表面在屏幕上投影所覆盖范围内的全部像素的深度值,依次访问屏幕范围内物体表面所覆盖的每一像素,用深度小(深度用z值表示,z值小表示离视点近)的像素点颜色替代深度 ...
- Google Code Jam 2010 Round 1B Problem B. Picking Up Chicks
https://code.google.com/codejam/contest/635101/dashboard#s=p1 Problem A flock of chickens are runn ...
- Google Code Jam 2010 Round 1A Problem A. Rotate
https://code.google.com/codejam/contest/544101/dashboard#s=p0 Problem In the exciting game of Jo ...
- Google Code Jam 2014 Round 1 A:Problem C. Proper Shuffle
Problem A permutation of size N is a sequence of N numbers, each between 0 and N-1, where each numbe ...
- The Art of Picking Intel Registers Intel寄存器的艺术
https://www.swansontec.com/sregisters.html I wrote this article for an online magazine called Scene ...
- Problem I: Ingenious Lottery Tickets
Problem I: Ingenious Lottery Tickets Your friend Superstitious Stanley is always getting himself int ...
- 1199 Problem B: 大小关系
求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...
- No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.
Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...
- C - NP-Hard Problem(二分图判定-染色法)
C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144 ...
随机推荐
- UIImage图片处理
#pragma mark - #pragma mark - 缩放处理 + (UIImage *)scaleImage:(UIImage *)image withScale:(float)scale { ...
- Apache-rhel5.8环境下编译安装
Apache安装过程 Step 1:安装包gcc或gcc-c++# yum install gcc#yum install gcc-c++ Step 2:安装包APR和APR-Utilapr-1.4. ...
- 前端JS模版库kino.razor - 原理流程分析 - 改进版轮子RazorJs
1.前言 从后台获取数据,在前端JS里面拼接字符串,不累吗?敢不敢找一款前端使使... 现在这种模板库比较多了,我用过的jquery-template .JsRender .听说过的一堆,还有各种MV ...
- Intellij Idea安装主题
IDEA中jar包形式的主题比较常见.(顺便给大家推荐一个主题站:http://www.ideacolorthemes.org/themes/) 从主菜单中依次选择[File]>[Import ...
- OutputCache各参数的说明
OutputCache各参数的说明 Duration 缓存时间,以秒为单位,这个除非你的Location=None,可以不添加此属性,其余时候都是必须的. Location Location当被设置为 ...
- Xcode 中添加 .pch文件
1 新建工程 2 创建 .pch文件 3 在setting里面进行设置:
- MySQL 基础 之 语句执行顺序
FORM: 对FROM的左边的表和右边的表计算笛卡尔积.产生虚表VT1 ON: 对虚表VT1进行ON筛选,只有那些符合<join-condition>的行才会被记录在虚表VT2中. JOI ...
- 已知TSP问题的最好解
a280 : 2579ali535 : 202339att48 : 10628att532 : 27686bayg29 : 1610bays29 : 2020berlin52 : 7542bier12 ...
- CDZSC_2015寒假新人(2)——数学 B
B - B Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
- 优化DOM交互
DOM操作与交互要消耗大量时间,所以优化DOM交互有重大意义. 1.最小化现场更新 如果需要访问的DOM部分是已经显示的页面的一部分,那么这就是在进行一个现场更新.现场更新得越多,代码完成执行所需要的 ...