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. Java数据库连接--JDBC调用存储过程,事务管理和高级应用

    相关链接:Jdbc调用存储过程 一.JDBC常用的API深入详解及存储过程的调用 1.存储过程的介绍 我们常用的操作数据库语言SQL语句在执行的时候要先进行编译,然后执行,而存储过程是在大型数据库系统 ...

  2. iOS oc和swift中协议的使用

    创建一个空的工程 在工程中我们新建一个类 继承与NSObject 定义一个协议‘ @protocol UpdateAlertDelegate <NSObject> //这里的红色字体就是我 ...

  3. POJ2479(dp)

    Maximum sum Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 39089   Accepted: 12221 Des ...

  4. HDU5832

    A water problem Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  5. T-SQL 语句

    表的创建:1.创建列(字段):列名+类型2.设置主键列(primary key):能够唯一标识一条数据3.设置唯一(unique):内容不能重复4.外键关系:一张表(从表)其中的某列引用自另外一张表( ...

  6. 编写JQuery插件-4

    封装对象方法的插件 jQuery.fn.extend() 的两种写法 以添加一个点击按钮为例: 方法一: (function ($) { $.fn.mask = function(options){ ...

  7. 使用python制作ArcGIS插件(1)工具介绍

    使用python制作ArcGIS插件(1)工具介绍 by 李远祥 ArcGIS从10.0开始支持addin(ArcGIS软件中又叫作加载项)的方式进行插件制作.相对于以往9.x系列,addin的无论是 ...

  8. Activity启动过程分析

    Android的四大组件中除了BroadCastReceiver以外,其他三种组件都必须在AndroidManifest中注册,对于BroadCastReceiver来说,它既可以在AndroidMa ...

  9. JS闭包深入理解(理解篇)

    看书的时候很是不明白为啥变量老是五,经过认真思考的出一下理解: function box() {   var arr = [];   for (var i = 0; i < 5; i++) {  ...

  10. JavaScript易混淆知识点小回顾--数组方法与字符串方法;

    数组属性: arr.length;查看数组的长度 arr.Pop;删除数组最后一个元素; 数组的方法: arr.push();添加到数组末端; arr.shift();删除数组的第一个元素; arr. ...