RT,求各位大佬告诉我是什么原因/kk/kk/kel
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#define pii pair<int,int>
#define mp make_pair
using namespace std;
const int N=205,M=25,K=105;
const int dx[5]={0,1,-1,0,0},dy[5]={0,0,0,1,-1};
inline char read() {
char ch=getchar();
while(ch=='\n'||ch==' ') ch=getchar();
return ch;
}
struct snake{
int num,len=0;
vector<pii>v;
}a[M];
bool vis[N][N];
int n,m,k,c,cnt;
char ch[N][N],st[N][N];
char mov[M][K];
void bfs(int x,int y,int num){
queue<pii>q;
q.push(mp(x,y));
vis[x][y]=1;
while(!q.empty()){
pii now=q.front();
q.pop();
x=now.first,y=now.second;
a[num].v.push_back(mp(x,y));
a[num].len++;
for(int i=1;i<=4;i++){
int tx=x+dx[i],ty=y+dy[i];
if(tx<1||tx>n||ty<1||ty>m||vis[tx][ty]||ch[tx][ty]!='#') continue;
vis[tx][ty]=1;
q.push(mp(tx,ty));
}
}
}
void snake_into_foods(int x){
// printf("???\n");
for(pii i:a[x].v)
ch[i.first][i.second]='&';
}
void insert(int x,int y){
ch[x][y]='@';
}
void update(int x,int y){
ch[x][y]='#';
}
void ddelete(int x,int y){
ch[x][y]='.';
}
void check(int x,int fx,int fy){
if(ch[fx][fy]=='#'||ch[fx][fy]=='@'){
a[x].len=0;
snake_into_foods(x);
}else if(ch[fx][fy]=='&'){
a[x].v.insert(a[x].v.begin(),mp(fx,fy));
insert(a[x].v[0].first,a[x].v[0].second);
update(a[x].v[1].first,a[x].v[1].second);
a[x].len++;
}else{
a[x].v.insert(a[x].v.begin(),mp(fx,fy));
insert(a[x].v[0].first,a[x].v[0].second);
update(a[x].v[1].first,a[x].v[1].second);
ddelete(a[x].v[a[x].v.size()-1].first,a[x].v[a[x].v.size()-1].second);
a[x].v.pop_back();
}
}
void top_move(int x){
int tx=a[x].v[0].first,ty=a[x].v[0].second;
int fx=tx-1,fy=ty;
check(x,fx,fy);
}
void bottom_move(int x){
int tx=a[x].v[0].first,ty=a[x].v[0].second;
int fx=tx+1,fy=ty;
check(x,fx,fy);
}
void left_move(int x){
int tx=a[x].v[0].first,ty=a[x].v[0].second;
int fx=tx,fy=ty-1;
check(x,fx,fy);
}
void right_move(int x){
int tx=a[x].v[0].first,ty=a[x].v[0].second;
int fx=tx,fy=ty+1;
check(x,fx,fy);
}
void solve(int x,int step){//那只蛇,第几步
if(!a[x].len) return;
if(mov[x][step]=='W') top_move(x);
else if(mov[x][step]=='S') bottom_move(x);
else if(mov[x][step]=='A') left_move(x);
else right_move(x);
}
void print(){
for(int i=1;i<=cnt;i++){
cout<<a[i].len<<' '<<a[i].num<<'\n';
}
int sum=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(ch[i][j]=='&')
sum++;
cout<<sum;
}
void debug(int x){
for(int i=0;i<=n+1;i++){
for(int j=0;j<=m+1;j++){
putchar(ch[i][j]);
}
putchar(10);
}
cout<<x<<endl;
}
int main(){
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
ch[i][j]=read();
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(ch[i][j]=='@'){
a[++cnt].num=cnt;
bfs(i,j,cnt);
}
}
}
for(int i=1;i<=cnt;i++)
for(int j=1;j<=k;j++)
mov[i][j]=read();
for(int i=0;i<=n+1;i++) ch[i][0]=ch[i][m+1]='@';
for(int i=0;i<=m+1;i++) ch[0][i]=ch[n+1][i]='@';
// solve(1,1);
// cout<<cnt<<endl;
for(int i=1;i<=k;i++)
for(int j=1;j<=cnt;j++){
solve(j,i);
// debug(i);
}
print();
}