切换到宽版
  • 9092阅读
  • 5回复

PROB The Tamworth Two [复制链接]

上一主题 下一主题
离线stevenjl
 

只看楼主 倒序阅读 0 发表于: 2006-02-01

2.2 PROB The Tamworth Two




TASK: ttwo
LANG: PASCAL

Compiling...
Compile: OK

Executing...
sending data (ttwo) ttwo /home/kolstad/trainweb

Test 1 OK [0.003 secs]
Test 2 OK [0.002 secs]
Test 3 OK [0.003 secs]
Test 4 OK [0.002 secs]
Test 5 OK [0.003 secs]
Test 6 OK [0.002 secs]
Test 7 OK [0.002 secs]
Test 8 OK [0.002 secs]
Test 9 OK [0.002 secs]

All tests OK.




Your program ('ttwo') produced all correct answers!  This is your
submission #25 for this problem.  Congratulations!




我实在想不出这道题如何判断“0”(抓不到的那种情况),所以只好耍赖了,运行150次如果还不行就结束,输出“0”,不知大家有什么好办法?


Dream Walker...
离线archimedes

只看该作者 1 发表于: 2006-02-02
网上的标程
  1. program ttwo;
  2. var
  3. fin,fout:text;
  4. map:array[1..10,1..10]of char;
  5. state:array[1..10,1..10,0..3,1..10,1..10,0..3]of boolean;
  6. dir:array[0..3]of record
  7.     x,y:integer;
  8.     end;
  9. time:longint;
  10. i,j,fx,fy,fd,cx,cy,cd:integer;
  11. begin
  12. assign(fin,'ttwo.in');
  13. reset(fin);
  14. for i:=1 to 10 do begin
  15.   for j:=1 to 10 do begin
  16.     read(fin,map[i,j]);
  17.     if map[i,j]='F' then begin fx:=i;fy:=j;end;
  18.     if map[i,j]='C' then begin cx:=i;cy:=j;end;
  19.   end;
  20.   readln(fin);
  21. end;
  22. close(fin);
  23. fillchar(state,sizeof(state),0);
  24. fd:=0;cd:=0;state[fx,fy,fd,cx,cy,cd]:=true;
  25. time:=0;
  26. dir[0].x:=-1;dir[0].y:=0;
  27. dir[1].x:=0;dir[1].y:=1;
  28. dir[2].x:=1;dir[2].y:=0;
  29. dir[3].x:=0;dir[3].y:=-1;
  30. assign(fout,'ttwo.out');
  31. rewrite(fout);
  32. repeat
  33.   if (fx+dir[fd].x=0) or (fx+dir[fd].x=11) or (fy+dir[fd].y=0) or (fy+dir[fd].y=11) or (map[fx+dir[fd].x,fy+dir[fd].y]='*') then fd:=(fd+1) mod 4 else begin fx:=fx+dir[fd].x;fy:=fy+dir[fd].y;end;
  34.   if (cx+dir[cd].x=0) or (cx+dir[cd].x=11) or (cy+dir[cd].y=0) or (cy+dir[cd].y=11) or (map[cx+dir[cd].x,cy+dir[cd].y]='*') then cd:=(cd+1) mod 4 else begin cx:=cx+dir[cd].x;cy:=cy+dir[cd].y;end;
  35.   if state[fx,fy,fd,cx,cy,cd] then begin
  36.     writeln(fout,0);
  37.     close(fout);
  38.     halt;
  39.   end;
  40.   inc(time);
  41.   state[fx,fy,fd,cx,cy,cd]:=true;
  42. until (fx=cx) and (fy=cy);
  43. writeln(fout,time);
  44. close(fout);
  45. end.
离线blueblood
只看该作者 2 发表于: 2006-07-06
如果出现farmer & cow同时回到某个他们曾经同时经过的地方(且方向一致), 就是无解了。
离线stevenjl

只看该作者 3 发表于: 2006-07-06
所以要记录啊~但是这个记录比较麻烦,不如穷举
Dream Walker...
离线archimedes

只看该作者 4 发表于: 2007-07-10
USACO Analysis 160000次后COW与FARMER比回到原处,<160000就行了
离线swj05652
只看该作者 5 发表于: 2007-08-07
lz的这种方法还算比较正大光明的
总比我无数题看答案好吧
快速回复
限100 字节
 
上一个 下一个