救命10RE,本人已自闭,望大佬来调
  • 板块P1746 离开中山路
  • 楼主CD43
  • 当前回复11
  • 已保存回复11
  • 发布时间2022/8/20 22:10
  • 上次更新2023/10/27 14:22:36
查看原帖
救命10RE,本人已自闭,望大佬来调
755114
CD43楼主2022/8/20 22:10
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int mmap[1001][1001],n,zh[1000001][4],head=1,tail=1,x,y,xx,yy;
string a;
int bfs(int x,int y,int xx,int yy)
{
	for(;;)
	{
		if(x==xx&&y==yy)
		{
//			cout<<"c:"<<zh[head][0]<<" "<<zh[head][1]<<" "
			return zh[head][2];
			
		}
		
		if(mmap[x+1][y]==1)
		{
			zh[tail][0]=x+1;
			zh[tail][1]=y;
			zh[tail][2]=zh[head-1][2]+1;
			tail++;
//			cout<<"a:"<<x+1<<" "<<y<<" "<<zh[head-1][2]+1<<endl;
		}
		if(mmap[x][y+1]==1)
		{
			zh[tail][0]=x;
			zh[tail][1]=y+1;
			zh[tail][2]=zh[head-1][2]+1;
			tail++;
//			cout<<"a:"<<x<<" "<<y+1<<" "<<zh[head-1][2]+1<<endl;
		}
		if(mmap[x-1][y]==1)
		{
			zh[tail][0]=x-1;
			zh[tail][1]=y;
			zh[tail][2]=zh[head-1][2]+1;
			tail++;
//			cout<<"a:"<<x-1<<" "<<y<<" "<<zh[head-1][2]+1<<endl;
		}
		if(mmap[x][y-1]==1)
		{
			zh[tail][0]=x;
			zh[tail][1]=y-1;
			zh[tail][2]=zh[head-1][2]+1;
			tail++;
//			cout<<"a:"<<x<<" "<<y-1<<" "<<zh[head-1][2]+1<<endl;
		}
		x=zh[head][0];
		y=zh[head][1];
		head++;
//		cout<<"b:"<<x<<" "<<y<<endl;
	}
}
int main(){
	std::ios::sync_with_stdio(false);//去同步优化
	cin.tie(0);//缓存优化 
	cout.tie(0);//缓存优化
	cin>>n;
	for(register int i(1);i<=n;i++)
	{
		cin>>a;
		for(int j(1);j<=n;j++)
		{
			mmap[i][j]=a[j-1]-47;
		}
	}
	cin>>x>>y>>xx>>yy;
	cout<<bfs(x,y,xx,yy);
	return 0;
}
//for (register int i(1); i <= n; ++ i)循环加速
//register int 变量定义优化
//inline 函数优化 
//cout<<111<<"\n";

本人已自闭,望大佬来调

2022/8/20 22:10
加载中...