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 ...
随机推荐
- freemarker报错之三
1.错误描写叙述 Expression students is undefined on line 30, column 24 in student.ftl. The problematic inst ...
- 我的第一个Servlet
学了一个学期JEE,明天就要考试了. 在3月份自己開始准备去努力的复习考研的高数还有英语等学科. 结果到如今才发现,虽说是考的计算机(本专业的)可是考研和技不可兼得. 想想自己没准备考研的时候的每天大 ...
- debian安装mysql
http://thirteen-tw.blogspot.com/2008/09/debian-mysql-server.html 安裝MySQL-Server debian:~# apt-get in ...
- 划分树 poj2104 hdu5249
KPI Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- Sprite Kit编程指南(1)-深入Sprite Kit
深入Sprite Kit 学习Sprite Kit最好的方法是在实践中观察它.此示例创建一对场景和各自的动画内容.通过这个例子,你将学习使用Sprite Kit内容的一些基础技术,包括: · ...
- for-in用法
var nyc = { fullName: "New York City", mayor: "Bill de Blasio", popu ...
- .Net Errors
1.Unknown column 'Extent1.Discriminator' in 'field list' Resole:http://blog.csdn.net/philip502/artic ...
- Android-----------国际化多国语言文件夹命名汇总
*如果不区分地区,则不加后面的-rxx内容 Arabic, Egypt (ar_rEG) —————————–阿拉伯语,埃及 Arabic, Israel (ar_rIL) ———————— ...
- 省市联动JQ封装比较简洁调用的方法
前言 因为省市联动的需求在每个项目几乎存在,所以本人也对此在web页面通过封装比较简洁的JQ方法循环判断调用调用后台获取数据再绑定到Select表单上.如果对代码有什么疑问或者更好办法可以在评论区留言 ...
- SPOJ 4206 Fast Maximum Matching (二分图最大匹配 Hopcroft-Carp 算法 模板)
题目大意: 有n1头公牛和n2头母牛,给出公母之间的m对配对关系,求最大匹配数.数据范围: 1 <= n1, n2 <= 50000, m <= 150000 算法讨论: 第一反应 ...