题目描述

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

错误贪心:两遍线段覆盖

错因:推样例

正确贪心:先按右端点从小到大排序,如果这个线段两台录像机都可以给,给结束时间晚的那个

#include<cstdio>
#include<algorithm>
using namespace std;
struct node
{
int s,t;
}e[];
bool cmp(node p,node q)
{
return p.t<q.t;
}
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d%d",&e[i].s,&e[i].t);
sort(e+,e+n+,cmp);
int ans=,end1=,end2=;
for(int i=;i<=n;i++)
{
if(e[i].s>=end1 && e[i].s>=end2)
{
end1>end2 ? end1=e[i].t : end2=e[i].t;
ans++;
}
else if(e[i].s>=end1)
{
end1=e[i].t;
ans++;
}
else if(e[i].s>=end2)
{
end2=e[i].t;
ans++;
}
}
printf("%d",ans);
}

[USACO14JAN]Recording the Moolympics的更多相关文章

  1. BZOJ3433: [Usaco2014 Jan]Recording the Moolympics

    3433: [Usaco2014 Jan]Recording the Moolympics Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 55  So ...

  2. 3433: [Usaco2014 Jan]Recording the Moolympics

    3433: [Usaco2014 Jan]Recording the Moolympics Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 137  S ...

  3. 【BZOJ】3433: [Usaco2014 Jan]Recording the Moolympics (贪心)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3433 想了好久啊....... 想不出dp啊......sad 后来看到一英文题解......... ...

  4. BZOJ 3433 [Usaco2014 Jan]Recording the Moolympics:贪心

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3433 题意: 给出n个区间[a,b). 有两个记录器,每个记录器中存放的区间不能重叠. 求 ...

  5. 【bzoj 3433】{Usaco2014 Jan} Recording the Moolympics(算法效率--贪心)

    题意:给出n个区间[a,b),有2个记录器,每个记录器中存放的区间不能重叠.求2个记录器中最多可放多少个区间. 解法:贪心.只有1个记录器的做法详见--关于贪心算法的经典问题(算法效率 or 动态规划 ...

  6. BZOJ-USACO被虐记

    bzoj上的usaco题目还是很好的(我被虐的很惨. 有必要总结整理一下. 1592: [Usaco2008 Feb]Making the Grade 路面修整 一开始没有想到离散化.然后离散化之后就 ...

  7. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  8. 关于贪心算法的经典问题(算法效率 or 动态规划)

    如题,贪心算法隶属于提高算法效率的方法,也常与动态规划的思路相挂钩或一同出现.下面介绍几个经典贪心问题.(参考自刘汝佳著<算法竞赛入门经典>).P.S.下文皆是我一个字一个字敲出来的,绝对 ...

  9. P2255 [USACO14JAN]记录奥林比克Recording the M…

    P2255 [USACO14JAN]记录奥林比克Recording the M… 题目描述 Being a fan of all cold-weather sports (especially tho ...

随机推荐

  1. Unicode和UTF-8

    作者:于洋链接:https://www.zhihu.com/question/23374078/answer/69732605来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出 ...

  2. Opendarlight Carbon 安装

    写在前面 目前最轻松的一次安装过程,感谢大翔哥的帮助. 安装过程 1.Zip包下载 找到Opendaylight官网,进入下载界面找到Carbon版本并下载. 2.Zip包解压 把这个zip压缩包解压 ...

  3. 团队Alpha冲刺(五)

    目录 组员情况 组员1(组长):胡绪佩 组员2:胡青元 组员3:庄卉 组员4:家灿 组员5:凯琳 组员6:翟丹丹 组员7:何家伟 组员8:政演 组员9:黄鸿杰 组员10:刘一好 组员11:何宇恒 展示 ...

  4. 福大软工1816:Beta(6/7)

    Beta 冲刺 (6/7) 队名:第三视角 组长博客链接 本次作业链接 团队部分 团队燃尽图 工作情况汇报 张扬(组长) 过去两天完成了哪些任务 文字/口头描述 组织会议 开发wxpy部分功能 展示G ...

  5. java沙盒入门(2)

    Java在Internet上的应用已经日渐普遍,使用在网页上的Java程序称之为applet,利用Applet的嵌入能够使原本静态的HTML富有变化,并且能够做到"声"." ...

  6. java一些知识

    类名前只有两种修饰符:不写(即default,但不能把default写上去)或public.默认不写则此类只能被同一包下的类调用以生成相应的实例.但若是public,则可以被不同包下的类调用以生成其实 ...

  7. MySQL 日志功能详解

    MySQL日志分类 1:查询日志 :query log     2:慢查询日志:slow_query_log 查询执行时长超过指定时长的查询操作所记录日志     3:错误日志:error log   ...

  8. [2017BUAA软工]第三次博客作业:案例分析

    第三次博客作业:案例分析 1. 调研和评测 1.1 BUG及设计缺陷描述 主要测试博客园在手机端上的使用情况. [BUG 01] 不能后退到上一界面(IOS) 重现步骤:打开博客首页中任意博文,点击博 ...

  9. 【Python】Python基础教程系列目录

    Python是一个高层次的结合了解释性.编译性.互动性和面向对象的脚本语言. 在现在的工作及开发当中,Python的使用越来越广泛,为了方便大家的学习,Linux大学 特推出了 <Python基 ...

  10. CODE FESTIVAL 2016 qualA Grid and Integers

    划年代久远的水 题意 有一个R*C的棋盘,要求在每个格子上填一个非负数,使得对任意一个2*2的正方形区域,左上角和右下角的数字之和等于左下角和右上角的数字之和.有一些格子已经被填上了数字,问现在能否满 ...