题目描述

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. listagg wm_concat 行转列

    一. 这个写法和wm_concat相似,listagg(day,',')要把哪一列转换为同一行within group (order by day)同一行如何排序 with temp as ( ' d ...

  2. IT小小鸟读后感言

    有感 读了我是一只IT小小鸟之后, 我发现上大学得靠自己自学,确定自己的目标和方向,多去参与实验和自己多锻炼编写程序.我现在大一,还有很多时间来让自己变得更好,虽然要补考两门课程,但是还是不要失去信心 ...

  3. DNS测试工具的使用(了解)

    dig命令, host命令, nslookup命令,rndc命令 dig命令(直接测试DNS性能,不会查询/etc/hosts文件) dig [-t RR_TYPE] name [@SERVER] [ ...

  4. BOM对象属性定时器的调用

    使count中的内容,自动切换 <body> <h1 id="count"></h1> </body> //获取count var ...

  5. 软工网络15团队作业4——Alpha阶段敏捷冲刺之Scrum 冲刺博客(Day1)

    概述 Scrum 冲刺博客对整个冲刺阶段起到领航作用,应该主要包含三个部分的内容: ① 各个成员在 Alpha 阶段认领的任务 ② 明日各个成员的任务安排 ③ 整个项目预期的任务量(使用整数表示,与项 ...

  6. java分页算法

    int totalPageNum = (totalRecord  +  pageSize  - 1) / pageSize;

  7. 在Delphi中动态地使用SQL查询语句 Adoquery sql 参数 冒号

    在Delphi中动态地使用SQL查询语句 在一般的数据库管理系统中,通常都需要应用SQL查询语句来提高程序的动态特性.下面介绍如何在Delphi中实现这种功能.在Delphi中,使用SQL查询语句的途 ...

  8. Web前端面试宝典(最新)

    第一部分:HTML问答题   1.简述一下你对HTML语义化的理解? 用正确的标签做正确的事情. html语义化让页面的内容结构化,结构更清晰,便于对浏览器.搜索引擎解析;即使在没有样式CSS情况下也 ...

  9. BZOJ3573 HNOI2014米特运输

    显然确定一个点的权值后整棵树权值确定.只要算出根节点的权值就能知道两种改法是否等价. 乘的话显然会炸,取log即可.map似乎会出一些问题,sort即可. #include<iostream&g ...

  10. 什么是P问题,NP问题和NPC问题

    转载自:Matrix67的博客 什么是P问题.NP问题和NPC问题 这或许是众多OIer最大的误区之一.    你会经常看到网上出现“这怎么做,这不是NP问题吗”.“这个只有搜了,这已经被证明是NP问 ...