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. 使用Docx.dll插入图片在Centos 7 上报错:system.DllNotFound:libgdiplus.so

    熬了N天,终于把WORD 文档打开替换.插入图片完好,部署,本机测试没有问题 可是一放到服务器(Centos 7) 就提示下面的错误: 度娘一下: https://www.cnblogs.com/xi ...

  2. n宫格的实现方法

    方法一.table 1.看成多列 <style> .line{ display: table; width: 1024px; clear:both; overflow:auto; /*-- ...

  3. logback的configuration

    logback的<configuration>只有三个属性: 1.scan[boolean]:当scan被设置为true时,当配置文件发生改变,将会被重新加载.默认值为true. 2.sc ...

  4. uLua学习之创建游戏对象(二)

    前言 上节,刚刚说到创建一个“HelloWorld”程序,大家想必都对uLua有所了解了,现在我们一步步地深入学习.在有关uLua的介绍中(在这里),我们可以发现它使用的框架是Lua + LuaJIT ...

  5. AppSettings和ConnectionStrings的辨析

    1.<connectionStrings> <connectionStrings> <add name="ConnectionStringName" ...

  6. 【强力卸载】使用Uninstall Tool卸载各类不易卸载的软件

    Uninstall Tool 经测试卸载MySql5.7.18成功. 下载地址: http://files.cnblogs.com/files/xiaohi/%E3%80%90%E8%BD%AF%E4 ...

  7. Cygwin 下的 自动安装工具 apt-cyg

    类似 于apt-get 或者 yum Cygwin可以在Windows下使用unix环境Bash和各种功能强大的工具,对于Linux管理员来说不想使用Linux桌面是必备的工具. Cygwin下也有类 ...

  8. 自行解决12306页面显示异常的问题(长城宽带下WWW。12306无法正常使用)

    前二天突然发现家里所用的长城宽带的www.12306.cn无法正常显示,点击余票查询或者车票预订均打不开,加载时间非常长,现象好似CSS等资源文件未载入成功(如图所示)更换chrome.firefox ...

  9. 2018.6.24 oracle数据库的 事务及视图

    第06章 事务及视图 本章内容  事务  视图 1 事务 1.1 什么是事务 事务也称工作单元,是一个或多个SQL语句组成的序列,这些个SQL操作作为一个完整的工作单元要么全部执行,要么全不执行. ...

  10. python_25_string

    name="my name is 齐志光qizhiguang" print(name.capitalize())#首字母变大写 print(name.count('i'))#统计字 ...