P2255 [USACO14JAN]记录奥林比克Recording the M…
P2255 [USACO14JAN]记录奥林比克Recording the M…
题目描述
Being a fan of all cold-weather sports (especially those involving cows),
Farmer John wants to record as much of the upcoming winter Moolympics as
possible.
The television schedule for the Moolympics consists of N different programs
(1 <= N <= 150), each with a designated starting time and ending time. FJ
has a dual-tuner recorder that can record two programs simultaneously.
Please help him determine the maximum number of programs he can record in
total. 冬奥会的电视时刻表包含N (1 <= N <= 150)个节目,每个节目都有开始和结束时间。农民约翰有两台录像机,请计算他最多可以录制多少个节目。
输入输出格式
输入格式:
Line 1: The integer N.
- Lines 2..1+N: Each line contains the start and end time of a single
program (integers in the range 0..1,000,000,000).
输出格式:
- Line 1: The maximum number of programs FJ can record.
输入输出样例
6
0 3
6 7
3 10
1 5
2 8
1 9
4
说明
INPUT DETAILS:
The Moolympics broadcast consists of 6 programs. The first runs from time
0 to time 3, and so on.
OUTPUT DETAILS:
FJ can record at most 4 programs. For example, he can record programs 1
and 3 back-to-back on the first tuner, and programs 2 and 4 on the second
tuner.
Source: USACO 2014 January Contest, Silver
分析
如果只有一台的话直接贪心即可,两台呢,贪心也可以,多加一个变量,记录另一台摄像机到什么时间了即可
额能会有几种情况:
- 两台摄像机都在拍摄节目,这个节目也就拍不成了
- 有一台摄像机空闲,那就选这台拍
- 两台都空闲,那么找两者结束之前拍摄较晚的继续拍下去,另外一台留给后面的拍,这样选择余地更多(浪费也少)
注意结束时间还是可以用的,他在结束时间的前一分钟已经拍完了,手动测试样例发现的,难怪我调试不对orz。
代码
#include<cstdio>
#include<algorithm>
using namespace std; struct Que{
int l,r;
bool operator < (const Que &a) const
{
return r < a.r;
}
}q[]; int main()
{
int n,ans = , last1 = -,last2 = -;
scanf("%d",&n);
for (int i=; i<=n; ++i)
scanf("%d%d",&q[i].l,&q[i].r);
sort(q+,q+n+);
for (int i=; i<=n; ++i)
{
if (q[i].l<last1&&q[i].l<last2) continue ;
ans++;
if (q[i].l>=last1&&q[i].l<last2) last1 = q[i].r;
else if (q[i].l<last1&&q[i].r>=last2) last2 = q[i].r;
else if (last1<last2) last2 = q[i].r;
else last1 = q[i].r;
}
printf("%d",ans);
return ;
}
P2255 [USACO14JAN]记录奥林比克Recording the M…的更多相关文章
- P2255 [USACO14JAN]记录奥林比克
P2255 [USACO14JAN]记录奥林比克 题目描述 农民约翰热衷于所有寒冷天气的运动(尤其是涉及到牛的运动), 农民约翰想录下尽可能多的电视节目. 为moolympics电视时间表由N个不同的 ...
- ITWorld:2014年全球最杰出的14位编程天才
近日,ITWorld 整理全球最杰出的 14 位程序员,一起来看下让我们膜拜的这些大神都有哪些?(排名不分先后) 1.Jon Skeet 个人名望:程序技术问答网站 Stack Overflow 总排 ...
- Linux学习笔记2_mysql安装
查看文件内容的命令有很多:cat, tac, more, less, head, tail, nl. cat由第一行开始显示档案内容:tac从最后一行开始显示,可以看出tac是cat的倒着写:more ...
- SecureCRT设置
SecureCRT设置 文章来源:http://blog.csdn.net/dongqinliuzi/article/details/39890569 本文主要介绍SecureCRT的使用方法和技巧. ...
- 转-SecureCRT设置
原帖地址:http://www.2cto.com/os/201410/341569.html 一.基本设置 1.修改设置 为了SecureCRT用起来更方便,需要做一些设置,需要修改的有如下几处: 1 ...
- ffmepg命令行参数
ffmpeg使用 有些选项在每个流中都必须指定,例如比特率bitrate或编解码codec.指定流的字符串一般都会有各参数名称和参数,如编解码"-codec:a:1 ac3"表明第 ...
- securecrt简介
SecureCRT是最常用的终端仿真程序,简单的说就是Windows下登录UNIX或Liunx服务器主机的软件,本文主要介绍SecureCRT的使用方法和技巧 VanDyke CRT 和 VanDyk ...
- SecureCRT 用法总结
SecureCRT 用法总结 1.下载与破解方法: Mac:https://www.jianshu.com/p/9427f12b1fdb Window:https://drive.google.c ...
- SecureCRT的安装、介绍、简单操作
网上看到一篇名为<SecureCRT的使用方法和技巧(详细使用教程)>的secureCRT教程,可能软件版本与我不一样我安装的是8.1. 原文来源:http://www.jb51.net/ ...
随机推荐
- cairo-dock天气位置代码
cairo-dock天气位置代码: 城市: 北京CHXX0008哈尔滨CHXX0046长春CHXX0010沈阳CHXX0119大连CHXX0019天津CHXX0133呼和浩特CHXX0249乌鲁木齐C ...
- Spring之Quartz定时任务和Cron表达式详解
1.定时业务逻辑类 public class ExpireJobTask { /** Logger */ private static final Logger logger = LoggerFact ...
- 原生js添加类名,删除类名
1.添加类名: document.getElementById("myDiv").classList.add('mystyle'); 2.删除类名: document.getEle ...
- Flash图表控件FusionCharts调整图表百分比大小
用户可以为图表的宽度和高度设置百分比值,用来替代绝对的像素值. 以百分比的方式调整图表,首先需要更新HTML代码,如下所示: <div id="chartContainer" ...
- Eucalyptus-NC管理
1.前言 Elastic Utility Computing Architecture for Linking Your Programs To Useful Systems (Eucalyptus) ...
- restesay部署学习过程中遇到的问题
Exception starting filter org.jboss.resteasy.plugins.serer.servlet.Filter30Dispatcherjava.lang.Class ...
- [SVN]TortoiseSVN报“500 Internal Server Error”错误的解决方法
背景:由于某种原因,本人重启了一下SVN服务的物理机,重启过后发现所有人访问SVN都报如下错误. 由于重启之前是没有做过任何改动,所以面对这个错误有点摸不着头脑,防火墙.网管.清缓存等方法都试过,还没 ...
- linux 命令——44 top (转)
top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器.下面详细介绍它的使用方法.top是 一个动态显示过程,即可以通过用户按键来不断刷 ...
- VS打包方法(安装和部署简介)——内含大量图片,密症慎入!
友情提示:内含大量文字.图片,密集恐惧症者慎入! 主要记述一下利用微软集成开发环境VS打包的方法和详细步骤. 1.新建打包工程 打开VS,文件->添加项目->新建项目(如图1),在添加新项 ...
- IOS 九宫图解锁(封装)
NJLockView.h /.m @class NJLockView; @protocol NJLockViewDelegate <NSObject> - (void)lockViewDi ...