USACO/ttwo

17 篇文章 0 订阅
12 篇文章 0 订阅

 

Translate:USACO/ttwo

来自"NOCOW"

跳转到: 导航, 搜索

The Tamworth Two

两只塔姆沃斯牛

译 by Jure 修订 by ForEverLeeR BOI '98? - Richard Forster

目录

[编辑] 题目描述

两只牛逃跑到了森林里。农夫John开始用他的经验追捕这两头牛。你的任务是模拟他们的行为(牛和John)。

追击在10x10的平面网格内进行。一个格子可以是:

一个障碍物, 两头牛(它们总在一起), 或者 农民John. 两头牛和农民John可以在同一个格子内(当他们相遇时),但是他们都不能进入有障碍的格子。

一个格子可以是:

. 空地 
* 障碍物 
C 两头牛 
F 农民John 

这里有一个地图的例子:

*...*.....
......*...
...*...*..
..........
...*.F....
*.....*...
...*......
..C......*
...*.*....
.*.*......

牛在地图里以固定的方式游荡。每分钟,它们可以向前移动或是转弯。如果前方无障碍且不会离开地图,它们会按照原来的方向前进一步。否则它们会用这一分钟顺时针转90度。

农民John深知牛的移动方法,他也这么移动。

每次(每分钟)农民John和两头牛的移动是同时的。如果他们在移动的时候穿过对方,但是没有在同一格相遇,我们不认为他们相遇了。当他们在某分钟末在某格子相遇,那么追捕结束。

读入十行表示农夫John,两头牛和所有障碍的位置的地图。每行都只包含10个字符,表示的含义和上面所说的相同,你可以确定地图中只有一个'F'和一个'C'.'F'和'C'一开始不会处于同一个格子中。

计算农夫John需要多少分钟来抓住他的牛,假设牛和农夫John一开始的行动方向都是正北(即上)。如果John和牛永远不会相遇,输出0。


PROGRAM NAME: ttwo

[编辑] INPUT FORMAT

第1-10行:

每行10个字符,表示如上文描述的地图。

[编辑] SAMPLE INPUT (file ttwo.in)

*...*.....
......*...
...*...*..
..........
...*.F....
*.....*...
...*......
..C......*
...*.*....
.*.*......

[编辑] OUTPUT FORMAT

输出一个数字,表示John需要多少时间才能抓住牛们。输出0,如果John无法抓住牛。

[编辑] SAMPLE OUTPUT (file ttwo.out)

const d:array[0..3,1..2] of longint=((-1,0),(0,1),(1,0),(0,-1));
var a:array[0..10] of string;
c,f:array[0..160000,1..3] of longint;
n,m,i,j,k,sum:longint;
procedure find;
var t,w,fx,fy,cx,cy,dx,dy,i,j,k:longint;
begin
 t:=0;
 while t<160000 do
  begin
   fx:=f[t,1]; fy:=f[t,2]; cx:=c[t,1]; cy:=c[t,2];
   k:=f[t,3]; j:=c[t,3];  {writeln(fx,' f ',fy); writeln(cx,' c ',cy);}
   dx:=fx+d[k,1]; dy:=fy+d[k,2];
   inc(t);
   if (dx>0) and (dy>0) and (dx<=10) and (dy<=10) then
   begin
   if a[dx,dy]='*' then
    begin f[t,1]:=fx; f[t,2]:=fy; f[t,3]:=(f[t-1,3]+1) mod 4;
    end else
   {if a[dx,dy]='.' then}//fuck 
    begin f[t,1]:=dx; f[t,2]:=dy; f[t,3]:=f[t-1,3]; end;
   end
   else
    begin
     f[t,1]:=fx; f[t,2]:=fy; f[t,3]:=(f[t-1,3]+1) mod 4;
    end;
   dx:=cx+d[j,1]; dy:=cy+d[j,2];
   if (dx>0) and (dy>0) and (dx<=10) and (dy<=10) then
    begin
     if a[dx,dy]='*' then
     begin c[t,1]:=cx; c[t,2]:=cy; c[t,3]:=(c[t-1,3]+1) mod 4;
     end else
     {if a[dx,dy]='.' then}
      begin c[t,1]:=dx; c[t,2]:=dy; c[t,3]:=c[t-1,3]; end;
    end
   else
    begin
     c[t,1]:=cx; c[t,2]:=cy; c[t,3]:=(c[t-1,3]+1) mod 4;
    end;
   if (f[t,1]=c[t,1]) and (f[t,2]=c[t,2]) then
    begin writeln(t); close(input); close(output); halt; end;
   {writeln(t);}
  end;
  writeln(0);
end;
begin
 assign(input,'ttwo.in'); assign(output,'ttwo.out');
 reset(input); rewrite(output);
 for i:=1 to 10 do
  begin
  readln(a[i]);
  for j:=1 to 10 do
   if a[i,j]='F' then begin f[0,1]:=i; f[0,2]:=j; f[0,3]:=0; end
   else
   if a[i,j]='C' then begin c[0,1]:=i; c[0,2]:=j; c[0,3]:=0; end;
  end;
  find;
 close(input); close(output);
end.



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值