P6207 TLE求调!!!
  • 板块学术版
  • 楼主credente
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/8/26 15:04
  • 上次更新2024/8/26 17:02:52
查看原帖
P6207 TLE求调!!!
1285014
credente楼主2024/8/26 15:04

#5#6#7#8#9 TLE

#10 RE已改

#include <bits/stdc++.h>
using namespace std;

struct node{
	int x,y;
	int from;
	int step;
}lst[226];

int n,m;
char a[16][16];
bool vis[16][16];

int dx[]={0,0,-1,1};
int dy[]={1,-1,0,0};

void out (int z)
{
	if(lst[z].from!=-1)
	{
		out(lst[z].from);
	}
	cout << lst[z].x << " " << lst[z].y << endl;
}

void bfs()
{
	int cl=1,op=1;
	lst[cl].x=1;
	lst[cl].y=1;
	lst[cl].from=-1;
	lst[cl].step=1;
	vis[1][1]=true;
	while(cl<=op)
	{
		for(int i=0;i<4;i++)
		{
			int tx=lst[cl].x+dx[i];
			int ty=lst[cl].y+dy[i];
			if(tx>=1&&tx<=n&&ty>=1&&ty<=m&&!vis[tx][ty]&&a[tx][ty]=='.')
			{
				++op;
				lst[op].x=tx;
				lst[op].y=ty;
				lst[op].from=cl;
				lst[op].step=lst[cl].step+1;
				vis[tx][ty]=true;
				if(tx==n&&ty==m)
				{
					out(op);
					exit(0);
				}
			}
		}
		cl++;
	}
}

int main()
{
	cin >> n >> m;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cin >> a[i][j];
		}
	}
	bfs();
	cout << "Noway!" << endl;
	return 0;
}
2024/8/26 15:04
加载中...