【BZOJ】3433: [Usaco2014 Jan]Recording the Moolympics (贪心)
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
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
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 (贪心)的更多相关文章
- BZOJ 3433 [Usaco2014 Jan]Recording the Moolympics:贪心
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3433 题意: 给出n个区间[a,b). 有两个记录器,每个记录器中存放的区间不能重叠. 求 ...
- 3433: [Usaco2014 Jan]Recording the Moolympics
3433: [Usaco2014 Jan]Recording the Moolympics Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 137 S ...
- BZOJ3433: [Usaco2014 Jan]Recording the Moolympics
3433: [Usaco2014 Jan]Recording the Moolympics Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 55 So ...
- 【bzoj 3433】{Usaco2014 Jan} Recording the Moolympics(算法效率--贪心)
题意:给出n个区间[a,b),有2个记录器,每个记录器中存放的区间不能重叠.求2个记录器中最多可放多少个区间. 解法:贪心.只有1个记录器的做法详见--关于贪心算法的经典问题(算法效率 or 动态规划 ...
- BZOJ 3430: [Usaco2014 Jan]Ski Course Rating(并查集+贪心)
题面 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 136 Solved: 90 [Submit][Status][Discuss] Descript ...
- bzoj 1783: [Usaco2010 Jan]Taking Turns【贪心+dp】
不知道该叫贪心还是dp 倒着来,记f[0][i],f[1][i]分别为先手和后手从n走到i的最大值.先手显然是取最大的,当后手取到比先手大的时候就交换 #include<iostream> ...
- BZOJ 3432: [Usaco2014 Jan]Cross Country Skiing (二分+染色法)
还是搜索~~可以看出随着D值的增大能到达的点越多,就2分d值+染色法遍历就行啦~~~ CODE: #include<cstdio>#include<iostream>#incl ...
- [bzoj 3048] [Usaco2013 Jan]Cow Lineup
[bzoj 3048] [Usaco2013 Jan]Cow Lineup Description 给你一个长度为n(1<=n<=100,000)的自然数数列,其中每一个数都小于等于10亿 ...
- BZOJ 1634: [Usaco2007 Jan]Protecting the Flowers 护花( 贪心 )
考虑相邻的两头奶牛 a , b , 我们发现它们顺序交换并不会影响到其他的 , 所以我们可以直接按照这个进行排序 ------------------------------------------- ...
随机推荐
- asp.net页面生命周期之页面的终结阶段
处理过回发事件之后,页面便为浏览器生成输出做好了准备.呈现阶段分为两部分:预呈现和标记生成.预呈现这个子阶段有两个事件表征,分别为:预处理和投递处理. PreRender事件 通过处理该事件,页面和控 ...
- VUE 内置指令
1.v-if v-else-if v-else <!DOCTYPE html> <html lang="zh"> <head> <meta ...
- 1、jQuery概述
JQuery基本功能 ① 访问和操作Dom元素 ② 控制页面样式 ③ 对页面事件的处理 ④ 大量插件在页面中的运用 ⑤ 与Ajax技术的完美结合 $(document).ready ...
- 获取当前View
在实际开发中LayoutInflater这个类还是非常有用的,它的作用类似于findViewById().不同点是LayoutInflater是用来找res/layout/下的xml布局文件,并且实例 ...
- Docker exec与Docker attach
转载博客地址:http://blog.csdn.net/halcyonbaby 新浪微博:@寻觅神迹 内容系本人学习.研究和总结,如有雷同,实属荣幸! ================== Docke ...
- (C#)Windows Shell 外壳编程系列1 - 基础,浏览一个文件夹
1 - 基础,浏览一个文件夹 我们知道,在win32中是以外壳名字空间的形式来组织文件系统的,在外壳名字空间里的每一个对象(注)都实现了一个IShellFolder的接口,通过这个接口我们可以直接查询 ...
- LNMP架构二
Nginx默认虚拟主机 1.首先修改nginx.conf文件,删除server及下面的,在http最后添加include vhost/*.conf; (指定虚拟主机目录,并读取以.conf结尾的文件) ...
- .NET面试题(一)
1.请编程遍历页面上所有TextBox控件并给它赋值为string.Empty? foreach (System.Windows.Forms.Control control in this.Contr ...
- mysql产生随机数并连接字符串
concat('a','b','c');//连接字符串 rand();//产生随机数 floor();//取整数 UPDATE user set reg_ip= concat(floor(RAND() ...
- django源码分析----Related继承结构
在django中关联关系大概可以分成many-to-one(foriegnkey).one-to-one.many-to-many 这三种.它们有如下的类结构 class RelatedField(F ...