题194.洛谷P1518 [USACO2.4]两只塔姆沃斯牛 The Tamworth Two


题194.洛谷P1518 [USACO2.4]两只塔姆沃斯牛 The Tamworth Two


一、题目

在这里插入图片描述
在这里插入图片描述

二、题解

本题没什么好说的,记录一下自己咋犯病的

#include <bits/stdc++.h>

using namespace std;

const int Inf=200000;
const int dx[4]={-1,0,1,0};//{0,1,0,-1};我可能真的疯了,我当时以为向上走是x不变,y加1,那样就变成列数加1,向右走了,唉,烦死了
const int dy[4]={0,1,0,-1};//{1,0,-1,0};

char field[100][100];

int main()
{
    pair<int,int> F,C;
    fill(field[0],field[0]+100*100,'*');
    for(int i=1;i<=10;i++)
    {
        for(int j=1;j<=10;j++)
        {
            cin>>field[i][j];
            if(field[i][j]=='F')
            {
                field[i][j]='.';
                F.first=i;
                F.second=j;
            }
            else if(field[i][j]=='C')
            {
                field[i][j]='.';
                C.first=i;
                C.second=j;
            }
        }
    }
    int i=0;
    int dF=0,dC=0;
    while(F!=C)
    {
        if(field[F.first+dx[dF]][F.second+dy[dF]]=='*')
        {
            dF=(dF+1)%4;
        }
        else
        {
            F.first+=dx[dF];
            F.second+=dy[dF];
        }
        if(field[C.first+dx[dC]][C.second+dy[dC]]=='*')
        {
            dC=(dC+1)%4;
        }
        else
        {
            C.first+=dx[dC];
            C.second+=dy[dC];
        }
        i++;
        if(i==Inf)
        {
            break;
        }
    }
    if(i==Inf)
    {
        cout<<"0"<<endl;
    }
    else
    {
        cout<<i<<endl;
    }
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值