求助,WA
  • 板块学术版
  • 楼主__Cby___
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/7/26 14:06
  • 上次更新2023/11/3 07:34:40
查看原帖
求助,WA
734049
__Cby___楼主2023/7/26 14:06

答案错误,原网站http://noi.openjudge.cn/ch0205/2727/ 我自己验证了好几遍都没问题,提交上去只有两分,请大佬门帮帮我这个蒟蒻错在哪里.帮帮蒟蒻.

#include <iostream>
#include <queue>
using namespace std;
struct node {
	int x, y, step;
};
int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 };
int main() {
	int a, b, sx = 0, sy = 0;
	queue<node> q;
	char c[30][30];
	int way[30][30];
	while(1){
		cin >> a >> b;
		if (a == 0 && b == 0)return 0;
		for (int i = 0; i < a; i++) {
			for (int j = 0; j < b; j++) {
				cin >> c[i][j];
				way[i][j] = 0;
				if (c[i][j] == '@') {
					sx = i; sy = j;
					way[i][j] = 1;
				}
			}
		}
		node a1;
		a1.x = sx;
		a1.y = sy;
		a1.step = 0;
		q.push(a1);
		bool y = 0;
		while (!q.empty()&&!y) {
			node t = q.front();
			q.pop();
			for (int i = 0; i < 4; i++) {
				if (t.x + dx[i] >= 0
					&& t.y + dy[i] >= 0
					&& t.x + dx[i] < a
					&& t.y + dy[i] < b
					&& way[t.x + dx[i]][t.y + dy[i]] == 0
					&& c[t.x + dx[i]][t.y + dy[i]] != '#') {


					node txt;
					txt.x = t.x + dx[i];
					txt.y = t.y + dy[i];
					txt.step = t.step + 1;
					if (c[txt.x][txt.y] == '*') {
						cout << txt.step << endl;
						y = 1;
						break;
					}
					q.push(txt);
					way[t.x + dx[i]][t.y + dy[i]] = 1;
				}
			}
		}
		if (!y)cout << -1 << endl;
	}
	return 0;
}

注:深搜会爆!!!!! 急!!!!

2023/7/26 14:06
加载中...