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; }
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个记录器中最多可放多少个区间.
* 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).
* Line 1: The maximum number of programs FJ can record.