3433: [Usaco2014 Jan]Recording the Moolympics

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 137  Solved: 89
[Submit][Status][Discuss]

Description

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个区间[a,b).有2个记录器.每个记录器中存放的区间不能重叠.

求2个记录器中最多可放多少个区间.

Input

* 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).

Output

* Line 1: The maximum number of programs FJ can record.

Sample Input

6
0 3
6 7
3 10
1 5
2 8
1 9

INPUT DETAILS: The Moolympics broadcast consists of 6 programs. The first runs from time 0 to time 3, and so on.

Sample Output

4

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.

HINT

 

Source

Silver 鸣谢Alegria_提供译文

题解:(呵呵哒我会告诉你我的第一反应是网络流?)

其实仔细看看后发现还是个贪心,只不过现在是两个容器= =,然后就是经典的右边界排序后O(n)乱搞了

 /**************************************************************
Problem:
User: HansBug
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ var
i,j,k,l,m,n,ans,l1,l2:longint;
a:array[..,..] of longint;
procedure swap(var x,y:longint);
var z:longint;
begin
z:=x;x:=y;y:=z;
end;
procedure sort(l,r:longint);
var i,j,x,y:longint;
begin
i:=l;j:=r;x:=a[(l+r) div ,];
repeat
while a[i,]<x do inc(i);
while a[j,]>x do dec(j);
if i<=j then
begin
swap(a[i,],a[j,]);
swap(a[i,],a[j,]);
inc(i);dec(j);
end;
until i>j;
if i<r then sort(i,r);
if l<j then sort(l,j);
end; begin
readln(n);
for i:= to n do readln(a[i,],a[i,]);
sort(,n);
for i:= to n do
begin
if (a[i,]>=l1) then
begin
l1:=a[i,];
inc(ans);
end
else if (a[i,]>=l2) then
begin
l2:=a[i,];
inc(ans);
end;
if l1<l2 then swap(l1,l2);
end;
writeln(ans);
readln;
end.

3433: [Usaco2014 Jan]Recording the Moolympics的更多相关文章

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

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

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

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

  3. BZOJ3433: [Usaco2014 Jan]Recording the Moolympics

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

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

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

  5. [USACO14JAN]Recording the Moolympics

    题目描述 Being a fan of all cold-weather sports (especially those involving cows), Farmer John wants to ...

  6. 【BZOJ】3432: [Usaco2014 Jan]Cross Country Skiing (bfs+二分)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3432 题目说要相互可达,但是只需要从某个点做bfs然后判断其它点是否可达即可. 原因太简单了.... ...

  7. BZOJ 3430: [Usaco2014 Jan]Ski Course Rating(并查集+贪心)

    题面 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 136 Solved: 90 [Submit][Status][Discuss] Descript ...

  8. bzoj3431 [Usaco2014 Jan]Bessie Slows Down

    Description [Brian Dean, 2014] Bessie the cow is competing in a cross-country skiing event at the wi ...

  9. BZOJ 3432: [Usaco2014 Jan]Cross Country Skiing (二分+染色法)

    还是搜索~~可以看出随着D值的增大能到达的点越多,就2分d值+染色法遍历就行啦~~~ CODE: #include<cstdio>#include<iostream>#incl ...

随机推荐

  1. atoi

    , KInvalid}; int g_nStatus=kValid; int StrToInt(const char *str) { g_nStatus=KInvalid; ; if((str!=NU ...

  2. Hadoop权威指南:压缩

    Hadoop权威指南:压缩 [TOC] 文件压缩的两个好处: 减少储存文件所需要的磁盘空间 加速数据在网络和磁盘上的传输 压缩格式总结: 压缩格式 工具 算法 文件扩展名 是否可切分 DEFLATE ...

  3. 在ubuntu linux 中编写一个自己的bash脚本

    在ubuntu linux 中编写一个自己的简单的bash脚本. 实现功能:终端中输入简单的命令(以pm为例(play music)),来实现音乐的播放.注:本人ununut中安装了audacious ...

  4. 如何一步一步用DDD设计一个电商网站(十三)—— 领域事件扩展

    阅读目录 前言 回顾 本地的一致性 领域事件发布出现异常 订阅者处理出现异常 结语 一.前言 上篇中我们初步运用了领域事件,其中还有一些问题我们没有解决,所以实现是不健壮的,下面先来回顾一下. 二.回 ...

  5. UI 常用(UIButton)

    1.手势 UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@sele ...

  6. java学习阶段三:运算符和结构学习

    import java.util.Scanner;/* * JAVA中运算符的学习: * 算术运算符:+.-.*./ 和 %,两个整数相除,结果还是整数. * 赋值运算符:=.+=.-=.*=./=. ...

  7. R语言从小木虫网页批量提取考研调剂信息

    一.从URL读取并返回html树     1.1 Rcurl包         使用Rcurl包可以方便的向服务器发出请求,捕获URI,get 和 post 表单.比R socktet连接要提供更高水 ...

  8. esri-leaflet入门教程(5)- 动态要素加载

    esri-leaflet入门教程(5)- 动态要素加载 by 李远祥 在上一章节中已经说明了esr-leaflet是如何加载ArcGIS Server提供的各种服务,这些都是服务本身来决定的,API脚 ...

  9. ASP.NET使用WebApi接口实现与Android客户端的交互(图片或字符串的接收与回传)

    最近在使用WebApi   做下记录 //此接口实现接收Android客户端上传的JSON格式的信息,并返回"nihao"字符串 [Route("ReceiveData& ...

  10. 【排序算法】快速排序算法 Java实现

    快速排序是C.R.A.Hoare于1962年提出的一种划分交换排序.它采用了一种分治的策略,通常称其为分治法(Divide-and-ConquerMethod). 基本思想 先从数组中找出一个数作为基 ...