码迷,mamicode.com
首页 > 其他好文 > 详细

BZOJ1113: [Poi2008]海报PLA

时间:2014-08-11 17:30:32      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   os   io   for   

1113: [Poi2008]海报PLA

Time Limit: 10 Sec  Memory Limit: 162 MB
Submit: 691  Solved: 412
[Submit][Status]

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

bubuko.com,布布扣

Sample Output

4

bubuko.com,布布扣

HINT

 

Source

题解:

ans最多等于n,那么什么情况下ans可以减小呢

首先如果减少了,肯定是贴了一张海报,覆盖住两张高度相同的矩形(宽度是打酱油的。。。)

那么就如果 h[i]=h[j] 那么就得保证 i 与 j 之间没有 比它们高度更小的了

咦?想到了什么,对了,单调栈!维护一个单调递减栈,当该元素=栈顶元素时ans--,并将栈顶元素弹栈

代码:

bubuko.com,布布扣
 1 var top,ans,i,n:longint;
 2     a,sta:array[0..260000] of longint;
 3 procedure init;
 4  begin
 5    readln(n);
 6    for i:=1 to n do readln(a[i],a[i]);
 7  end;
 8 procedure main;
 9  begin
10    top:=0;ans:=n;
11    a[n+1]:=-1;
12    for i:=1 to n+1 do
13     begin
14       while (top>0) and (a[i]<=a[sta[top]]) do
15        begin
16          if a[i]=a[sta[top]] then dec(ans);dec(top);
17        end;
18       inc(top);sta[top]:=i;
19     end;
20    writeln(ans);
21  end;
22 begin
23   assign(input,input.txt);assign(output,output.txt);
24   reset(input);rewrite(output);
25   init;
26   main;
27   close(input);close(output);
28 end.  
View Code

 

BZOJ1113: [Poi2008]海报PLA,布布扣,bubuko.com

BZOJ1113: [Poi2008]海报PLA

标签:des   style   blog   http   color   os   io   for   

原文地址:http://www.cnblogs.com/zyfzyf/p/3905121.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!