跳到正文

个人记录

1231154465rtghgjn

Zzy985约 2 分钟
原文

这是 2026年4月18日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

收录
2026年4月18日
更新
2026年4月18日
篇幅
约 2 分钟

版本

  1. v3当前
  2. v2
  3. v1
C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,s1,s2,s3,s4,t[501][501][3],m,sn;
char a[101][101];
struct bbb{
    int x,y,z,s;
};
void aaa(){
    queue<bbb> q;
    q.push({s1,s2,m,0});
    t[s1][s2][m]=1;
    while(q.size()){
        bbb b=q.front();
        q.pop();
        if(b.x==s3&&b.y==s4){
            return b.s;
        }
        if(b.z==0){
            int nx=b.x+1,ny=b.y;
            if(nx>n||a[nx][ny]=='x'||t[nx][ny][b.z]) continue;
            q.push({nx,ny,b.z,b,s+1});
            t[nx][ny][b.z]=1;
        }
        else if(b.z==1){
            
        }
    }
    return -1;
}
signed main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cin>>a[i][j];
            if(a[i][j]=='A') s1=i,s2=j;
            if(a[i][j]=='B') s3=i,s4=j;
        }
    }
    aaa();
	return 0;
}