为什么会这样
查看原帖
为什么会这样
1272259
cgxd楼主2024/4/17 21:27

提交后发现上面写着编译错误,可在devc++上运行的好好的啊

#include<bits/stdc++.h>
using namespace std;
int n, x1, y1, x2, y2;
vector<bitset<1005>> bs;
int vis[1005][1005];
complex<int> c1, c2;
complex<int> c[] = {complex<int>(1, 0), complex<int>(0, 1), complex<int>(-1, 0), complex<int>(0, -1)};
queue<complex<int>> q;
int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		reverse(s.begin(), s.end());
		bitset<1005> bs1(s);
		bs.push_back(bs1);
	}cin >> x1 >> y1 >> x2 >> y2;
	x1--, y1--, x2--, y2--;
	c1 = complex<int>(x1, y1);
	c2 = complex<int>(x2, y2);
	q.push(c1);
	while(q.size()){
		complex<int> comp(q.front());
		int x = comp.real(), y = comp.imag();
		int k = vis[x][y] + 1;
		q.pop();
		for(complex<int> c3: c){
			complex<int> c4(comp + c3);
			int x1 = c4.real(), y1 = c4.imag();
			if(x1 < 0 or x1 > n or y1 < 0 or y1 > n or bs[x1][y1])
				continue;
			vis[x1][y1] = k;
			q.push(c4);
			if(q.back() == c2){
				cout << k;
				return 0;
			}
		}
	}
}
2024/4/17 21:27
加载中...