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

如此辛苦 水过~~~

Posted by Coldlearn at 2011-09-21 08:46:13 on Problem 1753
const f:array[1..16]of longint=(%10011,%100111,%1001110,%10001100,
				%100110001,%1001110010,%10011100100,%100011001000,
				%1001100010000,%10011100100000,%100111001000000,%1000110010000000,
				%11000100000000,%111001000000000,%1110010000000000,%1100100000000000);
var 
	a:array[0..4,0..4]of longint;
	q,d:array[0..65536]of longint;
	u:array[0..65536]of boolean;
   	i,j,k,m,n,start:longint;

procedure init;
var i,j:longint;s:string;
begin
	start:=0;
  	for i:=1 to 4 do
	begin
		readln(s);	
		for j:=1 to 4 do
		begin
			if s[j]='w' then a[i,j]:=0;
			if s[j]='b' then a[i,j]:=1;
		end;
	end;
	for i:=1 to 4 do
	for j:=1 to 4 do
	inc(start,a[i,j] shl (16-((i-1)*4+j)));
	//writeln(start);
end;
procedure bfs;
var i,j,head,tail,now,nd:longint;
begin
  	fillchar(u,sizeof(u),true);
	u[start]:=false;q[1]:=start;d[1]:=0;
	head:=1;tail:=2;
	if (start=0)or(start=65536) then begin writeln('0');halt;end;
	while head<>tail do
	begin
		now:=q[head];
		if (now=0)or (now=65535) then begin writeln(d[head]);halt;end;
		for i:=1 to 16 do
		begin
			nd:=now xor f[i];
			if u[nd] then 
			begin
				u[nd]:=false;
				q[tail]:=nd;
				d[tail]:=d[head]+1;
				if (nd=0)or(nd=65535) then begin  writeln(d[tail]);halt;end;
				inc(tail);
			end;
		end;
		inc(head);
	end;
	writeln('Impossible');
end;
begin
      init;
      bfs;
end.
	

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator