ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1060. Flip Game

if WA9
Posted by yuanyuan 7 May 2009 11:48
if WA9, try to check

wwww
wwww
wwwb
wwbb

ans=1

My solution:

program p1060;
type
  frr=array[0..5,0..5] of boolean;
var
  f:frr;
  ans:byte;
procedure init;
  var
    i,j:byte;
    ch:char;
  begin
    fillchar(f,sizeof(f),true);
    for i:=1 to 4 do
      begin
        for j:=1 to 4 do
          begin
            read(ch);
            if ch='b'
              then f[i,j]:=false;
          end;
        readln;
      end;
  end;
function check(f:frr):boolean;
  var
    b:boolean;
    i,j:byte;
  begin
    b:=f[1,1];
    for i:=1 to 4 do
      for j:=1 to 4 do
        if f[i,j]<>b
          then exit(false);
    exit(true);
  end;
function min(a,b:byte):byte;
  begin
    if a<b
      then exit(a)
      else exit(b);
  end;
procedure find(f:frr;x,y,t:byte);
  begin
    if check(f)
      then begin
             ans:=min(ans,t);
             exit;
           end;
    if x>4
      then exit;
    if y=4
      then find(f,x+1,1,t)
      else find(f,x,y+1,t);
    f[x,y]:=not(f[x,y]);
    f[x-1,y]:=not(f[x-1,y]);
    f[x+1,y]:=not(f[x+1,y]);
    f[x,y-1]:=not(f[x,y-1]);
    f[x,y+1]:=not(f[x,y+1]);
    if y=4
      then find(f,x+1,1,t+1)
      else find(f,x,y+1,t+1);
  end;
procedure outit;
  begin
    if ans=17
      then writeln('Impossible')
      else writeln(ans);
  end;
begin
  init;
  ans:=17;
  find(f,1,1,0);
  outit;
end.

Edited by author 07.05.2009 11:48

Edited by author 07.05.2009 11:49
Re: if WA9
Posted by hehexiaobai 31 Jul 2010 19:45
Yeah !!

Thank you very much;

I had tried many times.