记录编号 |
13910 |
评测结果 |
AAAAA |
题目名称 |
画海岛地图 |
最终得分 |
100 |
用户昵称 |
maxiem |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.001 s |
提交时间 |
2009-10-13 21:15:56 |
内存使用 |
0.17 MiB |
显示代码纯文本
program island;
type node=record
x:array [1..8,1..5] of shortint;
y:array [1..8,1..5] of shortint;
end;
var
last,table:array [1..8,1..8] of boolean;
co,data:node;
n,i,j,tmp:byte;
s:integer;
function judge(i,j,l:byte):boolean;
var t,a,b,x,y:byte;
begin
if j+l-1>n then begin
judge:=false;
exit;
end;
if (j-1>0) and (table[i,j-1]) then begin
judge:=false;
exit;
end;
judge:=true;
for a:=j to j+l-1 do if (table[i,a]=true) then begin judge:=false; exit;end;
for a:=j to j+l-1 do begin
x:=0;y:=1;
for b:=1 to i-1 do if (table[b,a]=true) then break;
while b<i-1 do begin
inc(b);
if (table[b,a]=false) then if (b>1) and (table[b-1,j]) then inc(x) else if (b=1) then inc(x);
end;
inc(x);
if data.y[a,x]-1<0 then begin
judge:=false;
exit;
end;
end;
end;
procedure print;
var
flag:boolean;
k,i,j,l:integer;
begin
flag:=false;
for i:=1 to n do for j:=1 to n do if table[i,j]<>last[i,j] then begin
flag:=true;
break;
end;
for i:=1 to n do begin
k:=0;j:=1;
while j<=n do begin
while (j<=n) and (table[j,i]=false) do inc(j);l:=j;
while (j<=n) and (table[j,i]) do inc(j);inc(k);
if not((j-l=co.y[i,k]) or ((j-l=0) and (co.y[i,k]=-1))) then begin
flag:=false;
break;
end;
end;
end;
if flag then begin
inc(s);
writeln (s);
for i:=1 to n do begin
for j:=1 to n do if table[i,j] then write ('*') else write (' ');
writeln;
end;
last:=table;
end;
end;
procedure make(i,j,no:byte);
var
c,a,k:byte;
b:array [1..8] of 1..4;
begin
if i<>n+1 then begin
while j<=n do begin
fillchar(b,sizeof(b),0);
if judge(i,j,data.x[i,no]) then begin
for a:=j to j+data.x[i,no]-1 do table[i,a]:=true;
for a:=j to j+data.x[i,no]-1 do begin
k:=1;while data.y[a,k]=0 do inc(k);
b[a-j+1]:=k;
dec(data.y[a,k]);
end;
c:=data.x[i,no];data.x[i,no]:=0;
if data.x[i,no+1]<>-1 then make (i,j+c+1,no+1) else make (i+1,1,1);
data.x[i,no]:=c;
for a:=j to j+data.x[i,no]-1 do table[i,a]:=false;
for a:=j to j+data.x[i,no]-1 do inc(data.y[a,b[a-j+1]]);
j:=j+1;
end
else j:=j+1;
end;
end
else print;
end;
procedure init;
begin
fillchar(table,sizeof(table),0);
fillchar(last,sizeof(last),0);
s:=0;
for i:=1 to 8 do for j:=1 to 5 do begin
data.x[i,j]:=-1;
data.y[i,j]:=-1;
end;
assign (input,'island.in');
reset (input);
readln (n);
for i:=1 to n do begin
read (tmp);j:=0;
while tmp<>0 do begin
inc(j);
data.x[i,j]:=tmp;
read (tmp);
end;
readln;
end;
for i:=1 to n do begin
read (tmp);j:=0;
while tmp<>0 do begin
inc(j);
data.y[i,j]:=tmp;
read (tmp);
end;
readln;
end;
co:=data;
close (input);
end;
begin
init;
assign (output,'island.out');
rewrite (output);
make (1,1,1);
if s=0 then writeln ('no');
close (output);
end.