代码求调悬2关
  • 板块灌水区
  • 楼主linzichen120207
  • 当前回复8
  • 已保存回复8
  • 发布时间2024/7/11 11:20
  • 上次更新2024/7/11 12:43:28
查看原帖
代码求调悬2关
935855
linzichen120207楼主2024/7/11 11:20

代码RE

#include<bits/stdc++.h>
using namespace std;
int n,m,s;
bool a[205][205];
queue<int> qx,qy,kong;
int sum,dir[15][2]={{-2,-2},{-2,-1},{-2,1},{-2,2},{-1,-2},{-1,2},{1,-2},{1,2},{2,-2},{2,-1},{2,1},{2,2}};

void bfs(){
	while(!qx.empty()){
		int x=qx.front();
		int y=qy.front();
		if(x==1&&y==1){
			return;
		}
		qx.pop();
		qy.pop();
		if(x<1||x>100||y<1||y>100)
			continue;
		for(int i=0;i<12;i++){
			int xx=x+dir[i][0];
			int yy=y+dir[i][1];
			if(!a[xx][yy]){
				qx.push(xx);
				qy.push(yy);
				a[xx][yy]=1;
				s++;
			}
		}
	}
}
int main(){
	for(int i=1;i<=2;i++){
		memset(a+1,0,sizeof(a));
		qx=kong;
		qy=kong;
		s=0;
		cin>>n>>m;
		qx.push(n);
		qy.push(m);
		a[n][m]=1;
		bfs();
		cout<<s<<endl;
	}
	return 0;
}

帮帮孩子吧

找一下哪里访问越界了

2024/7/11 11:20
加载中...