chess
吐槽这道题。。。好烦燥。。。goto在pascal里面超时了啊!!!goto你妹啊。。。
题目大意:这个游戏是两个人轮流在4*4的格子中放棋子,一个人放满了一行或一列或一个对角线就算赢。
现在,小秋秋用X先手,已经下过许多步了。他想知道自己现在是否有必胜策略,以及最小的字典序走法。
完全的裸搜,但是要判断它是不是必胜策略的话,不管别人怎么走你都要赢才行。
program Neayo;uses sysutils; const inf='chess.in'; ouf='chess.out'; var f:array[1..4,1..4]of longint; i,j,ansx,ansy:longint; win,lose:boolean; function judge(x:longint):boolean; var num:longint; begin for i:=1 to 4 do begin num:=0; for j:=1 to 4 do if f[i,j]=x then inc(num) else break; if num=4 then exit(true); num:=0; for j:=1 to 4 do if f[j,i]=x then inc(num) else break; if num=4 then exit(true); end; num:=0; for i:=1 to 4 do if f[i,i]=x then inc(num) else break; if num=4 then exit(true); num:=0; for i:=1 to 4 do if f[i,5-i]=x then inc(num) else break; if num=4 then exit(true); exit(false); end; function dfs(time:longint):boolean; var i,j,x,y:longint; label 2; begin for i:=1 to 4 do for j:=1 to 4 do if f[i,j]=-1 then begin f[i,j]:=1; if judge(1) then begin f[i,j]:=-1;exit(true);end; for x:=1 to 4 do for y:=1 to 4 do if f[x,y]=-1 then begin f[x,y]:=0; if (judge(0))or(not dfs(time+1))then goto 2; f[x,y]:=-1; end; f[i,j]:=-1; exit(true); 2:begin f[i,j]:=-1; f[x,y]:=-1; end; end; exit(false); end; procedure init; var ch:char;st:string; x,y,i,j:longint; label 1,2,3; begin assign(output,ouf);assign(input,inf); reset(input);rewrite(output); readln(ch); while ch<>'$' do begin fillchar(f,sizeof(f),$ff); for i:=1 to 4 do begin readln(st); for j:=1 to 4 do begin ch:=st[j]; if ch='o'then f[i,j]:=0; if ch='x'then f[i,j]:=1; end; end; for i:=1 to 4 do for j:=1 to 4 do if f[i,j]=-1 then begin f[i,j]:=1; if judge(1) then goto 1; for x:=1 to 4 do for y:=1 to 4 do if f[x,y]=-1 then begin f[x,y]:=0; if (judge(0))or(not dfs(0))then goto 2; f[x,y]:=-1; end; goto 1; 2:begin f[i,j]:=-1; f[x,y]:=-1; end; end; writeln('#####'); goto 3; 1:writeln('(',i-1,',',j-1,')'); 3:ch:=ch; readln(ch); end; close(input); end; begin init; close(output); end.

浙公网安备 33010602011771号