文章

68

粉丝

691

获赞

24

访问

547.8k

头像
求大佬解答,这bfs怎么就卡到50分了呢
P1681 中南大学2018年机试题
发布于2020年6月3日 17:12
阅读数 11.0k

 

 

#include<iostream>
#include<string>
#include<string.h>
#include<cmath>
#include<vector>
#include<map>
#include<unordered_map>
#include<algorithm>
#include<queue>
using namespace std;

#pragma warning(disable:4996)
#define inf 0x3f3f3f3f
#define MAX 105
#define ll long long
#define vec vector<int>
#define P pair<int,int>

char a[MAX][MAX];
int dx[4] = { -1,1,0,0 }, dy[4] = { 0,0,-1,1 };//上下左右
int n, m, step[MAX][MAX], T, sx, sy, tx, ty, k, ang[MAX][MAX];

bool check(int x, int y) {
	if (x<1 || x>m || y<1 || y>n || a[x][y] == '*')return false;
	else return true;
}

bool bfs() {
	for (int i = 1; i <= m; i++)
		for (int j = 1; j <= n; j++)
			step[i][j] = inf;
	memset(ang, -1, sizeof(ang));
	queue<P> q; q.push(P(sx, sy)); 
	step[sx][sy] = 0;
	for (int i = 0; i < 4; i++) {
		int xx = sx + dx[i], yy = sy + dy[i];
		if (check(xx, yy)) {
			...
登录查看完整内容


登录后发布评论

2 条评论
KJaebye VIP
2022年3月13日 22:19

这个题的测试用例有一组好像有问题,没有输入地图大小

赞(0)
admin SVIP
2020年6月3日 23:59

这个题非常考验读题仔细程度,出题人有点反套路laugh

赞(0)