Description
你家刚买了一套新房,想邀请朋友回来庆祝,所以需要一个很大的举行餐桌,餐桌能容纳的人数等于餐桌的周长,你想买一个能容纳最多人的餐桌,餐桌的边必须跟房间的边平行。
给你的房间的设计,计算最多能邀请的客人数。
Input
第一行包含两个整数R和C(1<=R,C<=2000),表示房子的长和宽。
接下来R行每行S个字符(中间没有空格),“.”表示空白区域,“X”表示有障碍物,餐桌所占区域必须是空白的。
Output
输出最多能要求的客人数量。
分析
1.桌子一定是矩形
(生活经验)
2.请自行理解(反正我看了水解后一秒理解),很水的。
3.元宵*1 想出的水解(我就是理解他的)——
^(* ̄(oo) ̄)^
代码
var
f:array[0..2010,0..2010] of longint;
a:array[0..2010,0..2010] of boolean;
n,m,ans:longint;
i,j,k:longint;
c:char;
procedure main;
var
i,j,x,min:longint;
begin
fillchar(f,sizeof(f),0);
for i:=1 to n do
for j:=1 to m do
if a[i,j]
then
if not a[i-1,j]
then f[i,j]:=1
else f[i,j]:=f[i-1,j]+1;
for i:=1 to n do
for j:=1 to m do
if a[i,j] then
begin
x:=j;
min:=maxlongint;
while a[i,x] do
begin
if f[i,x]<min
then min:=f[i,x];
if ans<(x-j+1)*2+min*2
then ans:=(x-j+1)*2+min*2;
x:=x+1;
end;
end;
end;
begin
readln(n,m);
ans:=0;
for i:=1 to n do
begin
for j:=1 to m do
begin
read(c);
if c='.'
then a[i,j]:=true
else a[i,j]:=false;
end;
readln;
end;
for i:=0 to m+1 do
begin
a[0,i]:=false;
a[n+1,i]:=false;
end;
for i:=0 to n+1 do
begin
a[i,0]:=false;
a[i,m+1]:=false;
end;
main;
writeln(ans-1);
end.