BZOJ3039: 玉蟾宫&wikioi2491 玉蟾宫

2023-06-25,,

3039: 玉蟾宫

Time Limit: 2 Sec  Memory Limit: 128 MB
Submit: 430  Solved: 265
[Submit][Status]

Description

有一天,小猫rainbow和freda来到了湘西张家界的天门山玉蟾宫,玉蟾宫宫主蓝兔盛情地款待了它们,并赐予它们一片土地。
这片土地被分成N*M个格子,每个格子里写着'R'或者'F',R代表这块土地被赐予了rainbow,F代表这块土地被赐予了freda。
现在freda要在这里卖萌。。。它要找一块矩形土地,要求这片土地都标着'F'并且面积最大。
但是rainbow和freda的OI水平都弱爆了,找不出这块土地,而蓝兔也想看freda卖萌(她显然是不会编程的……),所以它们决定,如果你找到的土地面积为S,它们每人给你S两银子。

Input

第一行两个整数N,M,表示矩形土地有N行M列。
接下来N行,每行M个用空格隔开的字符'F'或'R',描述了矩形土地。

Output

输出一个整数,表示你能得到多少银子,即(3*最大'F'矩形土地面积)的值。

Sample Input

5 6
R F F F F F
F F F F F F
R R R F F F
F F F F F F
F F F F F F

Sample Output

45

HINT

对于50%的数据,1<=N,M<=200

对于100%的数据,1<=N,M<=1000

Source

Poetize4

题解:
这方法叫悬线法?学习了
蒟蒻不会一次单调栈求左右最远能扩展到哪儿,只能来两次了。。。
代码:

 uses math;
const maxn=+;
var s:ansistring;
a:array[..maxn,..maxn] of char;
h,l,r,sta:array[..maxn] of longint;
n,m,i,j,k,ans,top:longint;
procedure init;
begin
readln(n,m);
for i:= to n do
begin
k:=;
readln(s);
for j:= to length(s) do
if s[j]<>' ' then begin inc(k);a[i,k]:=s[j];end;
end;
end;
procedure main;
begin
h[]:=-;h[m+]:=-;
for i:= to n do
begin
for j:= to m do if a[i,j]='F' then inc(h[j]) else h[j]:=;
top:=;
for j:= to m+ do
begin
while (top>) and (h[j]<h[sta[top]]) do
begin
r[sta[top]]:=j-;dec(top);
end;
inc(top);sta[top]:=j;
end;
top:=;
for j:=m downto do
begin
while (top>) and (h[j]<h[sta[top]]) do
begin
l[sta[top]]:=j+;dec(top);
end;
inc(top);sta[top]:=j;
end;
for j:= to m do ans:=max(ans,h[j]*(r[j]-l[j]+));
end;
writeln(*ans);
end; begin
assign(input,'input.txt');assign(output,'output.txt');
reset(input);rewrite(output);
init;
main;
close(input);close(output);
end.

BZOJ3039: 玉蟾宫&wikioi2491 玉蟾宫的相关教程结束。

《BZOJ3039: 玉蟾宫&wikioi2491 玉蟾宫.doc》

下载本文的Word格式文档,以方便收藏与打印。