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 ...
随机推荐
- ASP.net ListItem Attributes 属性回传丢失的解决方案
该方法为网上整理 1. 新继承一个列表控件 新控件中重写两个方法: using System; using System.Collections.Generic; using System.Linq; ...
- 网络爬虫(3)--Beautiful页面解析
前面2节中对页面内容的访问都是直接通过标签访问的,这样虽然也可以达到解析页面内容的目的,但是在网页复杂,页面结构发生变化时,爬虫就失效了.为了使爬虫能够更加鲁棒的工作,我们需要学习通过 ...
- Selenium WebDriver 学习笔记
1. 打开VS2012 2. 新建工程(单元测试工程或控制台程序都可以, 看需求) 3. 工具->NuGet程序包管理器->程序包管理器控制台 4. 输入"Install-Pac ...
- 纯css实现下拉菜单
今天给大家分享一个纯html+css实现的下拉菜单.在此声明一点,源码并非出自本人之手,是同项目组一兄弟PLUTO写的.好东西嘛,所以果断拿出来和大家分享.如果有更好的想法或者建议,一定记得留言哦!好 ...
- $.getJson()和$.ajax()同步处理
一.前言 为什么需要用到同步,因为有时候我们给一个提交按钮注册提交表单数据的时候,在提交动作之前会进行一系列的异步ajax请求操作,但是页面js代码会按顺序从上往下面执行,如果你在这过程中进行了异步操 ...
- Struts2中的ActionContext
ActionContext(Action上下文) ActionContext介绍 通过上面用户注册例子的学习,我们知道Xwork与Web无关性,我们的Action不用去依赖于任何Web容器,不用和那些 ...
- Qt Creator下载
Qt官网 http://qt.digia.com qt的历史版本可以到http://download.qt-project.org/archive/qt/下载
- ExtJS 创建动态加载树
Ext 中导航树的创建有两种方式:1.首先将所有的数据读出来,然后绑定到前台页面.2.每点击一个节点展开后加载子节点.在数据量比较小的时候使用第一种方式加载的会快一些,然而当数据量比较大的时候,我还是 ...
- fddd
<script language="JavaScript" type="text/javascript"> function exportChart ...
- js 原型
1: function Person (name,age) { 2: this.name = name; 3: this.age = age; 4: } 5: 6: Person.prototyp ...