玄关七十分代码求调!
查看原帖
玄关七十分代码求调!
1120702
Arthur_Douglas楼主2024/5/14 16:27
#include<bits/stdc++.h>
using namespace std;
#define int short
int F[101][101];
struct node
{
	int pre;
	int step;
	int x , y;
}answer[10001];
int dx[] = {0 , 0 , -1 , 1 , -1 , -1 , 1 , 1};
int dy[] = {1 , -1 , 0 , 0 , -1 , 1 , -1 , 1};
bool vis[101][101];
int n , m;
void bfs()
{
	answer[1].pre = -1;
	answer[1].step = 0;
	answer[1].x = 1;
	answer[1].y = 1;
	int st = 1 , op = 1;
	while(st <= op)
	{
		for(int i = 0;i < 8;++ i)
		{
			int tx = answer[st].x + F[answer[st].x][answer[st].y] * dx[i];
			int ty = answer[st].y + F[answer[st].x][answer[st].y] * dy[i];
			if(tx >= 1 && tx <= n && ty >= 1 && ty <= m && !vis[tx][ty] && i != answer[st].pre)
			{
				vis[tx][ty] = true;
				if(tx == n && ty == m)
				{
					cout << answer[st].step + 1;
					return ;
				}
				else
				{
					++ op;
					answer[op].pre = i;
					answer[op].step = answer[st].step + 1;
					answer[op].x = tx;
					answer[op].y = ty;
				}
			}
		}
		++ st;
	}
	cout << "NEVER";
}
signed main()
{
	cin >> m >> n;
	for(int i = 1;i <= n;++ i)
	for(int j = 1;j <= m;++ j)
	cin >> F[i][j];
	vis[1][1] = true;
	bfs();
	return 0;
}

who can help me?who\ can\ help\ me?

2024/5/14 16:27
加载中...