我不信有人能调好我的代码
查看原帖
我不信有人能调好我的代码
1371996
lao2010123楼主2024/6/9 18:57
#include<bits/stdc++.h>
using namespace std;
int p[41][81],ans,d_pos[3][2]={{0,1},{1,0},{-1,0}};
int dfs(int x,int y,int fx,int fy){
	//cout << "dsf now at x:" << x << "\ty:" << y << "\n";
	if(x == fx && y == fy){
		//cout << "ans+1\n";
		ans++;
		return 0;
	}
	int nx,ny;
	for(int i=0;i<3;i++){
		nx = x+d_pos[i][1];
		ny = y+d_pos[i][0];
		if(nx < 0 || nx > 4 || ny < 0 || ny > 8){
			nx = nx;
		}else{
			if(p[nx][ny] == 0){
				p[nx][ny] = 1;
				dfs(nx,ny,fx,fy);
				p[nx][ny] = 0;
			}
		}
	}
	
}
int m_dpos[8][2] = {{-2,-1},{-1,-2},{1,-2},{2,-1},{2,1},{1,2},{-1,2},{-2,1}};
int main(){
	int fx,fy,mx,my;
	cin >> fx >> fy >> mx >> my;
	int nx,ny;
	for(int i=0;i<8;i++){
		nx = mx+m_dpos[i][0];
		ny = my+m_dpos[i][1];
		if(nx < 0 || nx > 4 || ny < 0 || ny > 8){
			nx = nx;
		}else{
			p[nx][ny] = 1;
		}
	}
	dfs(0,0,fx,fy);
	cout << ans;
	return 0;
}
 
这可是0分代码哦。
2024/6/9 18:57
加载中...