A.Activity planning
题目描述
There is a collection of n activities E={1,2,..,n}, each of which requires the same resource, such as
a lecture venue, etc., and only one activity at a time Use this resource. Each activity i has a start
time of si and an end time of fi and si<fi. If the activity i is selected, it occupies resources within
the time interval [si,fi). If the interval [si,fi) does not intersect the interval [sj,fj), then the activity i is
said to be compatible with the activity j. That is, when fi<=sj or fj<=si, the activity i is compatible
with the activity j . Choose the largest collection of activities that are compatible with each other.
输入格式
The first line is an integer n;
The next n line, two integers per line, si and fi.
输出格式
Excluding mutual and compatible maximum active number.
样例输入1
4
1 3
4 6
2 5
1 7
样例输出1
2
数据范围与提示
1<=n<=1000
这道题解法与杭电今年暑假不AC解法相同,采用贪心法
代码实例
#include<stdio.h> struct huodong
{
int begin;
int end;
} J[]; int main()
{
int n,i,j,sum,temp;
sum = ;
scanf("%d",&n);
for(i=; i<n; i++)
scanf("%d %d",&J[i].begin,&J[i].end);
for(i=; i<n-; i++)
{
for(j=; j<n-i-; j++)
{
if(J[j].end>J[j+].end)
{
temp = J[j].end;
J[j].end = J[j+].end;
J[j+].end = temp; temp = J[j].begin;
J[j].begin = J[j+].begin;
J[j+].begin = temp;
}
}
}
temp = J[].end;
for(i=; i<n; i++)
{
if(J[i].begin>=temp)
{
sum++;
temp = J[i].end;
}
}
printf("%d\n",sum);
return ;
}
A.Activity planning的更多相关文章
- No control record for Activity type 1000/4220/1442 in version 000 / 2017 activity planning/qty planning
No control record for Activity type 1000/4220/1442 in version 000 / 2017 activity planning/qty plann ...
- SAP BAPI一览 史上最全
全BADI一览 List of BAPI's BAPI WG Component Function module name Description Description Obj. Ty ...
- Software Engineering: 3. Project planning
recourse: "Software Engineering", Ian Sommerville Keywords for this chapter: planning sche ...
- Include promo/activity effect into the prediction (extended ARIMA model with R)
I want to consider an approach of forecasting I really like and frequently use. It allows to include ...
- EventBus实现activity跟fragment交互数据
最近老是听到技术群里面有人提出需求,activity跟fragment交互数据,或者从一个activity跳转到另外一个activity的fragment,所以我给大家介绍一个开源项目,EventBu ...
- Android—Service与Activity的交互
service-Android的四大组件之一.人称"后台服务"指其本身的运行并不依赖于用户可视的UI界面 实际开发中我们经常需要service和activity之间可以相互传递数据 ...
- Android:Activity+Fragment及它们之间的数据交换.
Android:Activity+Fragment及它们之间的数据交换 关于Fragment与Fragment.Activity通信的四种方式 比较好一点的Activity+Fragment及它们之间 ...
- Android中Activity处理返回结果的实现方式
大家在网上购物时都有这样一个体验,在确认订单选择收货人以及地址时,会跳转页面到我们存入网站内的所有收货信息(包含收货地址,收货人)的界面供我们选择,一旦我们点击其中某一条信息,则会自动跳转到订单提交界 ...
- 报错:You need to use a Theme.AppCompat theme (or descendant) with this activity.
学习 Activity 生命周期时希望通过 Dialog 主题测试 onPause() 和 onStop() 的区别,点击按钮跳转 Activity 时报错: E/AndroidRuntime: FA ...
随机推荐
- FDFDF
Linux(Centos)之安装Nginx及注意事项 1.Nginx的简单说明 a. Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器,期初开发的目的 ...
- Mysql进阶-day3
多实例介绍: mysql多实例就是一台服务器开启多个不同的服务端口(3306,3307),运行多个MySQL服务进程,这些服务进程通过不同的socket监听不同的服务端口来提供各自的服务端口. 这些m ...
- svn使用教程及常见问题解决方案
使用教程转自:http://www.cnblogs.com/armyfai/p/3985660.html SVN简介: 为什么要使用SVN? 程序员在编写程序的过程中,每个程序员都会生成很多不同的版本 ...
- 把bootstrap4 dropdown 的导航下拉菜单触发方式改为鼠标浮动触发
方法1: 原文: https://zzll.org/article/bootstrap4-xialacaidan 很简单,css中加入如下代码 .dropdown:hover>.dropdown ...
- cheerio数据抓取
很多语言都能写个爬虫抓取数据,js自然也可以,使用cheerio可以支持css检索,较快捷的获取需要的数据.首先,先把node.js给安装了.可到官网下载.安装好node.js后,使用npm安装che ...
- 简单说说Spring Security 使用(附加验证码登录,自定义认证)
先看官方文档:http://docs.spring.io/spring-security/site/docs/4.0.x/reference/htmlsingle/ spring security4已 ...
- js判断鼠标滚轴方向(向上或向下)
var num=1; $(document).on("mousewheel DOMMouseScroll", function (e) { var delta = (e.origi ...
- js实现简单的评论和回复功能(数组版)
var method={ getDate:function (a,b){ //获取当前日期 //a表示年月日直接的分隔符,b表示时分秒之间的分隔符 var dateStr="", ...
- the longest distance of a binary tree
版权声明:欢迎查看本博客.希望对你有有所帮助 https://blog.csdn.net/cqs_2012/article/details/24880735 the longest distance ...
- IE8崩溃在CElement::GetUpdatedLayoutWithContext
发了一个我们页游助手的版本时,测试报告在某些机器上点开某网站时崩溃 "0x637e5067指令引用的0x00000008内存,该内存不能为read",查看dump文件,堆栈如下: ...