http://www.lydsy.com/JudgeOnline/problem.php?id=3433

想了好久啊。。。。。。。

想不出dp啊。。。。。。sad

后来看到一英文题解。。。。。。。。。。

sad。

末端点排序。。。然后对于两个录像机有有两种情况

RECODER1(当前录制节目的区间):-----

RECODER1(当前录制节目的区间):-----------

因右端点排序,所以下一个区间大概是:-------------------

可以看出,此时显然不能转移

当这个区间的左端点大于等于recoder1的右端点时并且小于recoder2的右端点时,显然可以转移,且一定是recoder1去录制,而非recoder2(这里是显然的)

当这个区间的左端点大于recoder2的右端点时,显然也可以转移,但是此时一定是recoder2去录制

所以我们维护当前两个recoder的右端点即可

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr2(a, b, c) for1(i, 1, b) { for1(j, 1, c) cout << a[i][j]; cout << endl; }
#define printarr1(a, b) for1(i, 1, b) cout << a[i]; cout << endl
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=200;
int n, ans;
struct dat { int x, y; }a[N];
bool cmp(const dat &a, const dat &b) { return a.y<b.y; } int main() {
read(n);
for1(i, 1, n) read(a[i].x), read(a[i].y);
sort(a+1, a+1+n, cmp);
int ed1=0, ed2=0;
for1(i, 1, n) {
int x=a[i].x;
if(x<ed1) continue;
if(x<ed2) ed1=ed2, ed2=a[i].y, ++ans;
else ed2=a[i].y, ++ans;
}
print(ans);
return 0;
}

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

【BZOJ】3433: [Usaco2014 Jan]Recording the Moolympics (贪心)的更多相关文章

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

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

  2. 3433: [Usaco2014 Jan]Recording the Moolympics

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

  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. BZOJ 3430: [Usaco2014 Jan]Ski Course Rating(并查集+贪心)

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

  6. bzoj 1783: [Usaco2010 Jan]Taking Turns【贪心+dp】

    不知道该叫贪心还是dp 倒着来,记f[0][i],f[1][i]分别为先手和后手从n走到i的最大值.先手显然是取最大的,当后手取到比先手大的时候就交换 #include<iostream> ...

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

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

  8. [bzoj 3048] [Usaco2013 Jan]Cow Lineup

    [bzoj 3048] [Usaco2013 Jan]Cow Lineup Description 给你一个长度为n(1<=n<=100,000)的自然数数列,其中每一个数都小于等于10亿 ...

  9. BZOJ 1634: [Usaco2007 Jan]Protecting the Flowers 护花( 贪心 )

    考虑相邻的两头奶牛 a , b , 我们发现它们顺序交换并不会影响到其他的 , 所以我们可以直接按照这个进行排序 ------------------------------------------- ...

随机推荐

  1. JMeter 四:建立高级web测试计划

    发送带有Header的请求 参考:http://jmeter.apache.org/usermanual/build-adv-web-test-plan.html#header_manager Jme ...

  2. vue - config(index.js)

    描述:我想,这是调用最多的一个文件了吧(无论是dev,还是prod) 'use strict' // Template version: 1.3.1 // see http://vuejs-templ ...

  3. 细数Python的特殊方法一:集合类

    1. 特殊方法汇总列表     2. 仿集合类 __len__:返回对象的长度 __getitem__:获得某一项的值 __setitem__:设置莫一项的值 __delitem__删除某一项 __c ...

  4. 修改tcp数据内容

    http://blog.sina.com.cn/s/blog_6f0c85fb0100xi1x.html 2.6内核基于NetFilter处理框架修改TCP数据包实现访问控制 参考上面的钩子函数,结合 ...

  5. Java提高合集(转载)

    转载自:http://www.cnblogs.com/pony1223/p/7643842.html Java提高十五:容器元素比较Comparable&Comparator深入分析 JAVA ...

  6. hibernate 关系映射之 单向外键关联一对一

    这里的关系指的是对象与对象之间的关系 注解方式单向关联一对一: //这个类描述的husband是一个对应一个wife的 import javax.persistence.Entity; import ...

  7. 修改easyui panel 默认样式

    有这么个需求需要修改easyui panel头部中的背景色.于是根据panel中的最终被浏览器解析出来的类名,直接修改这个css样式,设置backgroud-color这个属性,发现不管用. 于是,就 ...

  8. <转>Oracle Stream Replication技术

    Stream 是Oracle 的消息队列(也叫Oracle Advanced Queue)技术的一种扩展应用. Oracle 的消息队列是通过发布/订阅的方式来解决事件管理.流复制(Stream re ...

  9. NoSQL(二)

    redis介绍 1.aof存储的文件会越来越大,当文件很大时我们可以进行一次rdb存储原来的aof文件就可以删除了,因为aof就相当与mysql中的binlog文件会一致增长,当redis里面的key ...

  10. AAtitit.随时间变色特效 ---包厢管理系统的规划titit.随

    Atitit.随时间变色特效 ---包厢管理系统的规划 1 流程滴定仪 定义的参数 颜色.位置(开始值,结束值,当前比值) >>返回数值 可以后期处理转成双位16进制码 分别定义复合颜色的 ...