。。。为啥第三十一行RE呢?
查看原帖
。。。为啥第三十一行RE呢?
677143
dream_contry楼主2023/7/2 09:32
#include<bits/stdc++.h>
using namespace std;
string mp[405];
bool vis[405][405];
int n,m,fx,fy,cnt = 0,num=1;
struct point{
	int x;
	int y;
};

const int dx[8]={-1,-2,-2,-1,1,2,2,1};
const int dy[8]={2,1,-1,-2,2,1,-1,-2};

void bfs(int x, int y){
	queue<point> q;
	point st;
	st.x = x;
	st.y = y;
	q.push(st);
	while (!q.empty()){
		point nt = q.front();
		q.pop();
		vis[nt.x][nt.y] = true ;
		for (int i = 0; i < 8; i++){
			int nx = nt.x + dx[i];
			int ny = nt.y + dy[i];
			if (nx >= 1 && nx <= n && ny >= 1 && ny <= m && !vis[nx][ny] && mp[nx][ny] ==-1){
				vis[nx][ny] = true ;
				mp[nx][ny]=num;
				q.push({nx,ny});
			}
		}
		num++;
	}
}

int main(){
	cin >>n>>m>>fx>>fy;
	memset(mp,-1,sizeof(mp));
	mp[fx][fy]=0;
	vis[fx][fy]=true;
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++){
			bfs(i, j);
		}
	}
	cout << cnt;
	return 0;
}
2023/7/2 09:32
加载中...