[Poi2008]海报PLA
Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1304 Solved: 896
[Submit][Status][Discuss]
Description
N个矩形,排成一排. 现在希望用尽量少的矩形海报Cover住它们.
Input
第一行给出数字N,代表有N个矩形.N在[1,250000] 下面N行,每行给出矩形的长与宽.其值在[1,1000000000]2 1/2 Postering
Output
最少数量的海报数.
Sample Input
5
1 2
1 3
2 2
2 5
1 4
1 2
1 3
2 2
2 5
1 4
Sample Output
4
HINT
直接单调栈吧,怎么搞都行
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<algorithm> 5 #include<cstring> 6 #define F(i,j,n) for(int i=j;i<=n;i++) 7 #define D(i,j,n) for(int i=j;i>=n;i--) 8 #define LL long long 9 #define MAXN 250005 10 using namespace std; 11 int ans,n,x,y,s[MAXN],t=0; 12 int main() 13 { 14 scanf("%d",&n); 15 ans=n; 16 scanf("%d%d",&x,&y); 17 s[++t]=y; 18 F(i,2,n) 19 { 20 scanf("%d%d",&x,&y); 21 while (t>0&&s[t]>y) t--; 22 if (s[t]==y) ans--; 23 s[++t]=y; 24 } 25 printf("%d ",ans); 26 }