70pts求调,能通过Py3随机数据
  • 板块P1301 魔鬼之城
  • 楼主KrisXJ
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/7/15 18:09
  • 上次更新2024/7/15 19:16:15
查看原帖
70pts求调,能通过Py3随机数据
784825
KrisXJ楼主2024/7/15 18:09
#include <bits/stdc++.h>
using namespace std;

int m,n;
int city[105][105],vis[105][105];
int pos[2][8]= {{0,0,1,-1,-1,-1,1,1},{1,-1,0,0,-1,1,-1,1}};
int step=99999999;



struct node
{
    int x,y,ban,ans;
};

queue<node> Q;

int main()
{
	memset(vis,0,sizeof(vis));
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cin>>city[i][j];
		}
	}
	node start;
	start.x=1,start.y=1,start.ans=0,start.ban=-1;
	Q.push(start);
	//cout<<city[2][1]<<endl;
	while(!Q.empty())
	{
		node now = Q.front();
		Q.pop();
		if(now.x == m && now.y == n)
		{
			cout<<now.ans;
			return 0;
		}
		for(int i=0;i<8;i++)
		{
			int x2,y2;
			if(i != now.ban)
			{
				x2 = now.x + city[now.x][now.y] * pos[0][i];
				y2 = now.y + city[now.x][now.y] * pos[1][i];
			}
			else{continue;}
			
			if(x2 >= 1 && x2 <= m && y2 >=1 && y2 <= n && !vis[x2][y2])
			{
				node next;
				next.ans=now.ans+1;
				next.x=x2;
				next.y=y2;
				next.ban=i;
				Q.push(next);
				//printf("( %d , %d ) added : %d\n",next.x,next.y,city[next.x][next.y]); //TEST
				vis[x2][y2] = 1;
			}
		}
	}
	cout<<"NEVER";
    return 0;
}
2024/7/15 18:09
加载中...