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 ...
随机推荐
- Cocos2d-x 3.0rc0版本号项目的创建和部署
<1>执行setup.py 依照提示.加入你须要加入的环境变量 <2>创建项目批处理文件Create-Cocos2d-x 3.0-Project.bat 内容例如以下: @ec ...
- [Hapi.js] Extending the request with lifecycle events
Instead of using middlware, hapi provides a number of points during the lifecycle of a request that ...
- phonegap环境配置与基本操作
一.开发环境配置: 1.工具环境安装: 安装java sdk 1.6以上版本号,Android Development Tools.ant,系统变量 Path后面加入 新增名稱 JAVA_HOME 值 ...
- CLR via C# - 基础拾遗
编译器开关设置 IL代码质量 JIT本地代码质量 /optimize- /debug-(默认设置) 未优化 优化 /optimize- /debug+(full/pdbonly) 未优化 未优化 /o ...
- HttpWebRequest上传文件(Excel等)
//上传代码/// <summary> /// 文件上传 /// </summary> /// <param name="strAddress"> ...
- UIView的常用方法
bringSubviewToFront: 把指定的子视图移动到顶层 - (void)bringSubviewToFront:(UIView *)view 参数 view 需要移到顶层的视图 conve ...
- OpenCV——IplImage
IplImage结构: typedef struct _IplImage { int nSize; /* IplImage大小 */ int ID; /* 版本 (=0)*/ int nChannel ...
- uva 1596 Bug Hunt
In this problem, we consider a simple programming language that has only declarations of one-dimensi ...
- [转]Cocos2d-x建工程时避免copy文件夹和库
原文链接: http://www.cnblogs.com/andyque/archive/2011/09/27/2192920.html 在上一篇教程中,我们演示了如何使用VS2010来新建一个工程 ...
- [C++程序设计]用指针变量作函数参数接收数组地址
#include <iostream> using namespace std; void select_sort(int *p, int n) { int i, j, k; ; i &l ...