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.

输入输出样例

输入样例#1:

6
0 3
6 7
3 10
1 5
2 8
1 9
输出样例#1:

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…的更多相关文章

  1. P2255 [USACO14JAN]记录奥林比克

    P2255 [USACO14JAN]记录奥林比克 题目描述 农民约翰热衷于所有寒冷天气的运动(尤其是涉及到牛的运动), 农民约翰想录下尽可能多的电视节目. 为moolympics电视时间表由N个不同的 ...

  2. ITWorld:2014年全球最杰出的14位编程天才

    近日,ITWorld 整理全球最杰出的 14 位程序员,一起来看下让我们膜拜的这些大神都有哪些?(排名不分先后) 1.Jon Skeet 个人名望:程序技术问答网站 Stack Overflow 总排 ...

  3. Linux学习笔记2_mysql安装

    查看文件内容的命令有很多:cat, tac, more, less, head, tail, nl. cat由第一行开始显示档案内容:tac从最后一行开始显示,可以看出tac是cat的倒着写:more ...

  4. SecureCRT设置

    SecureCRT设置 文章来源:http://blog.csdn.net/dongqinliuzi/article/details/39890569 本文主要介绍SecureCRT的使用方法和技巧. ...

  5. 转-SecureCRT设置

    原帖地址:http://www.2cto.com/os/201410/341569.html 一.基本设置 1.修改设置 为了SecureCRT用起来更方便,需要做一些设置,需要修改的有如下几处: 1 ...

  6. ffmepg命令行参数

    ffmpeg使用 有些选项在每个流中都必须指定,例如比特率bitrate或编解码codec.指定流的字符串一般都会有各参数名称和参数,如编解码"-codec:a:1 ac3"表明第 ...

  7. securecrt简介

    SecureCRT是最常用的终端仿真程序,简单的说就是Windows下登录UNIX或Liunx服务器主机的软件,本文主要介绍SecureCRT的使用方法和技巧 VanDyke CRT 和 VanDyk ...

  8. SecureCRT 用法总结

    SecureCRT 用法总结   1.下载与破解方法: Mac:https://www.jianshu.com/p/9427f12b1fdb Window:https://drive.google.c ...

  9. SecureCRT的安装、介绍、简单操作

    网上看到一篇名为<SecureCRT的使用方法和技巧(详细使用教程)>的secureCRT教程,可能软件版本与我不一样我安装的是8.1. 原文来源:http://www.jb51.net/ ...

随机推荐

  1. unobtrusive验证,ajax局部加载后验证失效解决方法

    页面加载后运行此代码 $(function() {$.validator.unobtrusive.parse($("form")); }); 原因: 页面加载后unobtrusiv ...

  2. 安装mysql-installer-community

    1.在官网上下载mysql-installer-community-5.6.25.0 2.选择MySQL Installer 3.选择Windows (x86, 32-bit), MSI Instal ...

  3. Spring MVC + Thymeleaf

    参考网址: https://www.cnblogs.com/litblank/p/7988689.html 一.简介 1.Thymeleaf 在有网络和无网络的环境下皆可运行,而且完全不需启动WEB应 ...

  4. centos 安装 freeswitch,开启与关闭

    ---恢复内容开始--- 官网说明地址 :https://freeswitch.org/confluence/display/FREESWITCH/CentOS+7+and+RHEL+7 1.获取源码 ...

  5. sql server 索引总结三

    一.非聚集索引维护 非聚集索引的行定位器值保持相同的聚集索引值,即使该聚集索引列物理上重新定位后,也是如此. 为了优化这个维护开销,SQL Server添加一个指向旧数据页的指针,以在页面分割之后指向 ...

  6. crontab配置shell实现后台进程不间断运行

    检测get_report_no.php进程是否一直在运行 #!/bin/bash PROC=`ps -ef |grep get_report_no.php|grep -v grep|wc -l` if ...

  7. hihoCoder #1044 : 状态压缩·一 (清垃圾)

    题意: 某车厢有一列座位,共有n个位置,清洁工要在这n个位置上清垃圾,但是不能全部位置都清理,只能选择部分.选择的规则是,连续的m个位置内,不能够清理超过q个,也就是说从第1~m个位置最多可以清q个, ...

  8. File 与 Log #3--动态加入控件,[图片版]访客计数器(用.txt档案来记录)

    File 与 Log #3--动态加入控件,[图片版]访客计数器(用.txt档案来记录) 以前的两篇文章(收录在书本「上集」的第十七章) 请看「ASP.NET专题实务」,松岗出版 File 与 Log ...

  9. ubuntu openstack windows 镜像制作

    openstack  windows 镜像制作 首先下载windows所需要的驱动,virtio-win-1.1.16.vfd virtio-win-0.1-59.iso 下载的官方地址是: http ...

  10. go语言,安装包fetch error 问题解决方案

    最近需要安装grequests,出现了下面的error [fdf@zxmrlc ~]$ go get github.com/levigross/grequests package golang.org ...