加载中…
个人资料
sacredfantasy
sacredfantasy
  • 博客等级:
  • 博客积分:0
  • 博客访问:3,313
  • 关注人气:0
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
相关博文
推荐博文
谁看过这篇博文
加载中…
正文 字体大小:

usaco 2.4.1 ttwo

(2009-04-28 21:42:10)
标签:

usaco

2.4.1

ttwo

杂谈

分类: OI题解

一道水题,一次AC,而且也快:

Compiling...
Compile: OK

Executing...
   Test 1: TEST OK [0.000 secs, 208 KB]
   Test 2: TEST OK [0.000 secs, 208 KB]
   Test 3: TEST OK [0.011 secs, 204 KB]
   Test 4: TEST OK [0.000 secs, 208 KB]
   Test 5: TEST OK [0.000 secs, 204 KB]
   Test 6: TEST OK [0.011 secs, 204 KB]
   Test 7: TEST OK [0.000 secs, 204 KB]
   Test 8: TEST OK [0.000 secs, 208 KB]
   Test 9: TEST OK [0.011 secs, 208 KB]

All tests OK.

YOUR PROGRAM ('ttwo') WORKED FIRST TIME!  That's fantastic
-- and a rare thing.  Please accept these special automated
congratulations.

program ttwo;
var map:array[1..10,1..10]of char;
 xc,yc,xf,yf,x1,y1,x2,y2,fc,ff:integer;
 total:longint;
procedure zh1;
begin
 case x1 of
  0:if y1=1 then begin x1:=1;y1:=0;fc:=3; end else begin x1:=-1;y1:=0;fc:=1;end;
  -1:begin x1:=0;y1:=1;fc:=2;end;
  1:begin x1:=0;y1:=-1;fc:=4;end;
 end;
end;
procedure zh2;
begin
 case x2 of
  0:if y2=1 then begin x2:=1;y2:=0;ff:=3;end else begin x2:=-1;y2:=0;ff:=1;end;
  -1:begin x2:=0;y2:=1;ff:=2;end;
  1:begin x2:=0;y2:=-1;ff:=4;end;
 end;
end;
procedure main;
var c,f:boolean;
begin
 while total<160000 do  //超过这个次数会产生死锁
 begin
  c:=false;f:=false;
  //cow
  if (map[xc+x1,yc+y1]<>'*')then
  case fc of
   1:if xc<>1 then c:=true;
   2:if yc<>10 then c:=true;
   3:if xc<>10 then c:=true;
   4:if yc<>1 then c:=true;
  end;
  if c then begin
   xc:=xc+x1;
   yc:=yc+y1;
  end
  else zh1;
  //farmer
  if (map[xf+x2,yf+y2]<>'*')then
  case ff of
   1:if xf<>1 then f:=true;
   2:if yf<>10 then f:=true;
   3:if xf<>10 then f:=true;
   4:if yf<>1 then f:=true;
  end;
  if f then begin
   xf:=xf+x2;
   yf:=yf+y2;
  end
  else zh2;
  inc(total);
  if (xc=xf)and(yc=yf) then begin writeln(total);halt;end;
 end;
 writeln(0);
end;
procedure init;
var i,j:integer;
begin
 total:=0;
 x1:=-1;y1:=0;fc:=1;
 x2:=-1;y2:=0;ff:=1;
 for i:=1 to 10 do
 begin
  for j:=1 to 10 do
  begin
   read(map[i,j]);
   if map[i,j]='C' then //cow
    begin
     xc:=i;
     yc:=j;
    end;
   if map[i,j]='F' then //farmer
    begin
     xf:=i;
     yf:=j;
    end;
  end;
  readln;
 end;
end;
begin
  assign(input,'ttwo.in');
  reset(input);
  assign(output,'ttwo.out');
  rewrite(output);
  init;
  main;
  close(input);
  close(output);
end.

0

阅读 评论 收藏 转载 喜欢 打印举报/Report
  • 评论加载中,请稍候...
发评论

    发评论

    以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

      

    新浪BLOG意见反馈留言板 电话:4000520066 提示音后按1键(按当地市话标准计费) 欢迎批评指正

    新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 会员注册 | 产品答疑

    新浪公司 版权所有