红绿灯 保存下我一直段错误的代码

#include
#include<string.h>
#include
#include
using namespace std;
int stx,sty,lax,lay;int m,n;int flag;

vector a[100000],book[100000];

struct node{
int x,y,step;
}temp;

int main(){
int t;cin>>t;
while(t–){
queue q;
flag=0;
int m,n;cin>>m>>n;int ti;
for(int i=1;i<=m;i++){
a[i].clear();
a[i].push_back(0);
book[i].clear();
book[i].push_back(0);
}
for(int i=1;i<=m;i++){
for(int j=1;j<=n;j++){
cin>>a[i][j];
}

	}
	cin>>stx>>sty>>lax>>lay;
	if(stx==lax&&sty==lay) cout<<"0"<<endl;
	else{
	temp.x=stx;temp.y=sty;temp.step=0;
	q.push(temp);
	while(!q.empty()){
		temp=q.front();
		q.pop();
		int tx=temp.x,ty=temp.y,tstep=temp.step;

// cout<<tx<<" “<<ty<<” “<<endl;
if(txlax&&tylay){
cout<<tstep<<endl;
flag=1;
break;
}
int jiou=tstep%2;
if(jiou==0&&a[tx][ty]0||jiou1&&a[tx][ty]==1){
int zx=tx+1;
if(zx>m||zx<1||ty>n||ty<1||book[zx][ty]==1);
else{
book[zx][ty]=1;temp.x=zx;temp.y=ty;temp.step=tstep+1;
q.push(temp);
}
zx=tx-1;
if(zx>m||zx<1||ty>n||ty<1||book[zx][ty]==1) ;
else{
book[zx][ty]=1;temp.x=zx;temp.y=ty;temp.step=tstep+1;
q.push(temp);
}
}
else{
int zy=ty+1;
if(tx>m||tx<1||zy>n||zy<1||book[tx][zy]==1);
else{
book[tx][zy]=1;temp.x=tx;temp.y=zy;temp.step=tstep+1;
q.push(temp);
}
zy=ty-1;
if(tx>m||tx<1||zy>n||zy<1||book[tx][zy]1);
else{
book[tx][zy]=1;temp.x=tx;temp.y=zy;temp.step=tstep+1;
q.push(temp);
}
}
}
if(flag
0) cout<<”-1"<<endl;
}
}
}

猜你喜欢

转载自blog.csdn.net/weixin_43806345/article/details/88672450