usaco:The Tamworth Two

这是一个用C++实现的简单模拟程序,模拟农场上狐狸追逐小鸡的过程。程序通过定义地图、角色移动规则及捕获条件来追踪双方的位置变化,直至狐狸捕获小鸡或达到最大步数限制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/*
ID: Jang Lawrence
PROG: ttwo
LANG: C++
*/
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#define mp make_pair
using namespace std;
typedef long long lng;
typedef pair<int, int> pii;
char m[11][11];
bool is[11][11];
int dir[][2]={-1,0,0,1,1,0,0,-1};
bool can(int x,int y)
{
    return x>=0&&x<10&&y>=0&&y<10&&is[x][y];
}
struct role
{
  int x,y,d;
   void move()
   {
       int kx=x+dir[d][0],ky=y+dir[d][1];
       if(can(kx,ky)) x=kx,y=ky;
       else
       d=(d+1)%4;
   }
}f,c;
bool g()
{
    return f.x==c.x&&f.y==c.y;
}
int main()
{
  #ifndef  DEBUG
  freopen("ttwo.in","r",stdin);
  freopen("ttwo.out","w",stdout);
  #endif
for(int i=0;i<10;++i)
{
    for(int j=0;j<10;++j)
    {m[i][j]=getchar();
    if(m[i][j]=='*') is[i][j]=0;
    else is[i][j]=1;
    if(m[i][j]=='F')
    f.x=i,f.y=j,f.d=0;
    else
    if(m[i][j]=='C')
    c.x=i,c.y=j,c.d=0;
    }
    getchar();
}
int res=0;
while(1)
{
    f.move();
    c.move();
    res++;
    if(g()) break;
    if(res>160000)
    {
        res=0;
        break;
    }
}
printf("%d\n",res);
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值