Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 一A纪念...

Posted by The_Dawn at 2011-03-21 23:29:57 on Problem 1414
```今天身体虚弱，精神疲惫，写出来的程序七零八落，竟然一A了...

type
pos=record
x,y:longint;
end;
const
d:array[1..6,1..2]of integer=((-1,-1),(-1,0),(0,-1),(0,1),(1,0),(1,1));
var
map:array[0..11,0..11]of integer;
point:array[1..100]of pos;
posi:array[0..11,0..11]of longint;
a:array[0..100,0..100]of boolean;
zero:array[1..100]of integer;
i,j,k,ans,n,p,cot,coz,tmp:longint;
v,vis:array[0..100]of boolean;

procedure init;
var
i,j:longint;
begin
cot:=0;coz:=0;ans:=-maxlongint;
fillchar(a,sizeof(a),false);
for i:=1 to n do
begin
for j:=1 to i do
begin
inc(cot);
point[cot].x:=i;
point[cot].y:=j;
posi[i,j]:=cot;
if map[i,j]=0 then
begin
inc(coz);
zero[coz]:=cot;
end;
end;
end;

end;

procedure connect;
var
i,j:longint;
begin
for i:=1 to n do
for j:=1 to i do
begin
if j<>1 then
begin
a[posi[i,j-1],posi[i,j]]:=true;
a[posi[i,j],posi[i,j-1]]:=true;
end;
if i<>n then
begin
a[posi[i,j],posi[i+1,j]]:=true;
a[posi[i+1,j],posi[i,j]] :=true;
a[posi[i,j],posi[i+1,j+1]]:=true;
a[posi[i+1,j+1],posi[i,j]]:=true;
end;
end;
end;

function judge(p,clr:integer):boolean;
var
i,np:longint;
begin
vis[p]:=true;
v[p]:=true;
for i:=1 to 6 do
begin
np:=posi[point[p].x+d[i,1],point[p].y+d[i,2]];
if (a[p,np])and(map[point[np].x,point[np].y]=clr)and(not vis[np]) then
judge(np,clr);
end;
end;

function dfs(o:longint):longint;
var
i,j,tp,np:integer;
begin
tp:=0;
fillchar(v,sizeof(v),0);
fillchar(vis,sizeof(vis),0);
map[point[o].x,point[o].y]:=p;

for i:=1 to coz do if zero[i]<>o then
for j:=1 to 6 do
begin
vis[zero[i]]:=true;
v[zero[i]]:=true;
np:=posi[point[zero[i]].x+d[j,1],point[zero[i]].y+d[j,2]];
if a[np,zero[i]] then
begin

judge(np,map[point[np].x,point[np].y]);
end;
end;

for i:=1 to cot do if not v[i] then
if map[point[i].x,point[i].y]<>p then inc(tp) else dec(tp);
map[point[o].x,point[o].y]:=0;
exit(tp);
end;

begin
//assign(input,'1.txt');
//assign(output,'2.txt');
//reset(input);rewrite(output);

repeat
if (n=0)and(p=0) then break;
init;
connect;
for i:=1 to coz do
begin
tmp:=dfs(zero[i]);
if tmp>ans then ans:=tmp;
end;
writeln(ans);
until false;

//close(input);close(output);
end.

```

Followed by: