样例没过,(我是蒟蒻)
  • 板块P1443 马的遍历
  • 楼主cso666
  • 当前回复1
  • 已保存回复1
  • 发布时间2025/1/23 17:29
  • 上次更新2025/1/23 20:45:52
查看原帖
样例没过,(我是蒟蒻)
1513597
cso666楼主2025/1/23 17:29

用的dfs,不知道为啥,试了好几个数据都不会出现-1,特别奇怪

#include<iostream>
using namespace std;
int n,m,x,y;
int board[405][405];
bool check(int hx,int hy){
	if(hx<=n&&hy<=m&&hx>=0&&hy>=0)return 1;
	return 0;
}
void dfs(int hx,int hy,int step){
	if(step<board[hx][hy]||board[hx][hy]==-1){
		board[hx][hy]=step;
		if(check(hx-1,hy+2))dfs(hx-1,hy+2,step+1);
		if(check(hx+1,hy+2))dfs(hx+1,hy+2,step+1);
		if(check(hx-1,hy-2))dfs(hx-1,hy-2,step+1);
		if(check(hx+1,hy-2))dfs(hx+1,hy-2,step+1);
		if(check(hx-2,hy+1))dfs(hx-2,hy+1,step+1);
		if(check(hx-2,hy-1))dfs(hx-2,hy-1,step+1);
		if(check(hx+2,hy+1))dfs(hx+2,hy+1,step+1);
		if(check(hx+2,hy-1))dfs(hx+2,hy-1,step+1);
	}
	
}
int main(){
	for(int i=0;i<405;i++){
		for(int j=0;j<405;j++){
			board[i][j]=-1;
		}
	}
	cin>>n>>m>>x>>y;
	x--;
	y--;
	dfs(x,y,0);
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cout<<board[i][j]<<"    ";
		}
		cout<<"\n";
	}
	return 0;
}

=) 您的电脑 颠佬没有任何问题,我们也不会为你重新启动,且把你的所有隐私上传到网络上=)
完成:-114514%

2025/1/23 17:29
加载中...