3433: [Usaco2014 Jan]Recording the Moolympics

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 55  Solved: 34
[Submit][Status]

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

题解:
随便打了个贪心居然就过了23333,是数据弱还是怎么?
将区间按右端点排序,维护now[0],now[1]分别表示两个记录器最后的位置
新来的线段先往now大的那个记录器放,放不下再到小的那个里,否则会出现大材小用。。。(提示:过不了样例。。。)
不知道对不对???挖坑,以后来想。
代码:
 #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 1000
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int now[],n,ans;
struct rec{int x,y;}a[maxn];
inline bool cmp(rec a,rec b)
{
return a.y<b.y;
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();
for1(i,n)a[i].x=read(),a[i].y=read();
sort(a+,a+n+,cmp);
now[]=now[]=;
for1(i,n)
{
if(a[i].x>=now[])ans++,now[]=a[i].y;
else if(a[i].x>=now[])ans++,now[]=a[i].y;
if(now[]>now[])swap(now[],now[]);
}
printf("%d\n",ans);
return ;
}

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

  1. 3433: [Usaco2014 Jan]Recording the Moolympics

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

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

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

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

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

  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. server的散热和Linux中温度的检測

    当server被放在散热条件不好的条件下,这样会导致硬盘驱动过早损坏,而且server其它的组件也会非常快出现问题. 现代的server主板检測到CPU过热的时候,一般会限制CPU的频率,所以即使se ...

  2. 头像上传ASP.NET MVC实现-可拖动大小实时预览

    这是一个ASP.NET MVC实现的类似于dz论坛的上传头像功能.可以拖动选择大小,支持多种尺寸生成. 效果界面 头像上传源码下载 项目中具体应用时,请根据需求做调整.欢迎交流~回复即可下载~源码下载 ...

  3. 线程在WPF中的使用

    项目中可能会有这样的需求,一直获取新的某个数据信息,但仍不影响其他的操作功能,这时就用到了线程,获取新数据放到线程中操作,对其他操作不产生影响,下面就以随机获取数组中项为例解说WPF中使用线程这一实例 ...

  4. 再探Java基础——String.format(String format, Object… args)的使用

    最近看到类似这样的一些代码:String.format("参数%s不能为空", "birthday"); 以前还没用过这功能不知咐意思,后研究了一下,详细讲解如 ...

  5. Android 仿Win8的metro的UI界面(上)

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/23441455 昨晚没事手机下载了一些APP,发现现在仿win8的主界面越来越多, ...

  6. IO-文件 File 复制 读写 总结

    一定要注意: 传入的参数,应该是包含文件名的完整路径名,不能把一个文件复制到[文件夹]中,因为[文件夹]本身是不能有输入输出流的,只能复制到一个[文件]中,否则会报异常. 以字节流读写的三种方式 pu ...

  7. W3C小组宣布:HTML5标准制定完成

    近日,W3C小组宣布已经完成对HTML5标准以及Canvas 2D性能草案的制定,这就意味着开发人员将会有一个稳定的“计划和实施”目标. Web性能工作组已经推出W3C的两个版本建议草案. Navig ...

  8. parent.location.href和location.href区别

    parent.location.href='ind.php'parent用于框架结构,需要全网页转向如果你的网页是左右框架,那么,直接把当前页面全部转到ind.php中 location.href=' ...

  9. js设置元素的onclick传参方法

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD ...

  10. android 屏幕适配1 ——dimens.xml的适配

    1.如果是才开始做项目,已经有设计图:720*1280 1).默认values文件夹:1dp=1px values/dimens_x.xml: name: x1~x720   value:1px~72 ...