bfs为什么不对啊
  • 板块P1644 跳马问题
  • 楼主XacmER
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/3/16 15:35
  • 上次更新2023/10/23 21:25:09
查看原帖
bfs为什么不对啊
676573
XacmER楼主2023/3/16 15:35
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#define x first
#define y second
using namespace std;
typedef pair<int,int> PII;
const int N = 20;
int dx[4] = {1,2,1,2};
int dy[4] = {2,1,-2,-1};
int res;
int n,m;
int bfs(){
	queue<PII> q;
	q.push({0,0});
	while(q.size()){
		PII t = q.front();
		q.pop();
		for(int i = 0;i < 4;i++){
			int a = t.x + dx[i],b = t.y + dy[i];
			if(a < 0 || a > n || b < 0 || b > m) continue;
			if(a == n && b == m) res++;
			q.push({a,b});
		}
	}
	return res;
}
int main(){
	cin >> n >> m;
	cout << bfs();
	return 0;
}
```cpp
2023/3/16 15:35
加载中...