您的位置:首页 > 其它

2017.04.15【NOIP2017提高组】模拟赛B组 T3:菱形内的计数

2017-04-18 10:26 295 查看
Description

  教主上电视了!这个消息绝对是一个爆炸性的新闻。一经传开,大街上瞬间就没人了(都回家看电视去了),商店打烊,工厂停业。大家都把电视机的音量开到最大,教主的声音回响在大街小巷。

  小L给小X慌乱地打开自己家的电视机,发现所有频道都播放的是教主的采访节目(-_-bbb)。只见电视屏幕上的教主笑意吟吟,给大家出了一道难题:

  一个边长为n的大菱形被均匀地划分成了n*n个边长为1的小菱形组成的网格,但是网格中部分边被抹去了,小L想知道,大菱形内有多少个平行四边形,这些平行四边形内不存在边。

  教主说,如果谁写出了程序,移动用户请将程序发送到xxxx,联通用户请将程序发送到xxxx……如果答对这个题,将有机会参加抽奖,大奖将是教主签名的Orz教主T-Shirt一件!这个奖品太具有诱惑力了。于是你需要编一个程序完成这么一道题。

Input

  输入的第1行为一个正整数n,为大菱形的边长。

  以下2n行,每行2n个字符,字符为空格,“/”,“\”中的一个。

  前n行,第i行中居中有2i个字符,这2i个字符中位置为奇数的字符只可能为“/”或者空格,位置为偶数的字符只可能为“\”或空格,若为空格表示这样一条边不存在,其余字符均为空格,描述了大菱形的上半部分。

  后n行,第i行居中有有2(n-i+1)个字符,与上半部分类似地描述了菱形的下半部分

  输入文件保证大菱形的轮廓上没有边被抹去。

Output

  输出仅包括一个整数,为满足要求的平行四边形个数。

Sample Input

3

/\

/\/\

/ /\ \

\/\ /

\ \/

\/

Sample Output

3

Data Constraint

Hint

【数据规模】

  对于20%的数据,n≤10;

  对于40%的数据,n≤60;

  对于60%的数据,n≤200;

  对于100%的数据,n≤888。

题解:

这道题,首先就把菱形压成一个(2n+1)*(2n+1)矩形。

于是,我们就去找一个点上面是-和左边是|的一个点。然后就一直向下延伸,直到找到一个点数-。往右一直延长,直到找到一个|。然后就判断以延伸到的点来判断一个平行四边形合不合理。A。

时间用理性思维去想,是不会超的。

标程:

var
i,j,k,l,n,m,x,y,ex,ey,ans:longint;
a:array[1..1777,1..1777] of longint;
bz:array[1..1777,1..1777] of boolean;
pd,jl:boolean;
s:ansistring;
procedure gc;
var
i,j,k,l:longint;
begin
for i:=x to ex-1 do
begin
if i mod 2=0 then
if a[i,ey]=0 then
begin
pd:=false;
jl:=false;
break;
end;
end;
for j:=y to ey-1 do
begin
if j mod 2=0 then
if a[ex,j]=0 then
begin
pd:=false;
jl:=false;
break;
end;
end;
for i:=x to ex-1 do
begin
for j:=y to ey-1 do
begin
if a[i,j]>0 then
begin
pd:=false;
jl:=false;
break;
end;
end;
end;
pd:=false;
end;
begin
fillchar(bz,sizeof(bz),true);
readln(n);
for i:=1 to n do
begin
readln(s);
for j:=1 to length(s) do
if s[j]<>' ' then
begin
break;
end;
x:=i*2;
y:=1;
for k:=1 to length(s)-2*(j-1) do
begin
if s[k+n-i]='/' then
a[x,y]:=1
else
if s[k+n-i]='\' then
a[x,y]:=2;
inc(y);
dec(x);
end;
end;
for i:=1 to n do
begin
readln(s);
x:=n*2+1;
y:=i*2;
for j:=i to 2*n-i+1 do
begin
if s[j]='/' then
a[x,y]:=1
else
if s[j]='\' then
a[x,y]:=2;
dec(x);
inc(y);
end;
end;
pd:=false;
for x:=2 to 2*n do
begin
for y:=2 to 2*n do
begin
if (a[x-1,y]=2) and (a[x,y-1]=1) and (bz[x,y]) then
begin
pd:=true;
jl:=true;
for i:=x+1 to n*2+1 do
begin
if i mod 2=0 then continue;
if a[i-1,y-1]=0 then
begin
pd:=false;
jl:=false;
break;
end;
if a[i,y]=2 then
begin
ex:=i;
for j:=y+1 to n*2+1 do
begin
if j mod 2=0 then continue;
if a[x-1,j-1]=0 then
begin
pd:=false;
jl:=false;
break;
end;
if a[x,j]=1 then
begin
ey:=j;
gc;
if pd=false then break;
end;
end;
end;
if pd=false then break;
end;
if jl then
begin
for i:=x to ex-1 do
begin
for j:=y to ey-1 do
begin
bz[i,j]:=false;
end;
end;
inc(ans);
end;
end;
end;
end;
writeln(ans);
end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: