0分求调!!(深搜)
查看原帖
0分求调!!(深搜)
1068194
H_M_B_C_楼主2024/7/9 17:55

我觉得我的思路没错,但是不仅样例没过,提交后只有两个测试点WA,其余RE

#include <bits/stdc++.h>
using namespace std;
//bool
long long  a[1000000][3];//vis[10000][3],
long long n,m,cnt;

int dx[12]={-2,-1,1,2, -2,-1,1,2 ,  2,-2,2,-2};
int dy[12]={1,2,2,1, -1,-2,-2,-1  , 2,2,-2,-2};

void dfs(long long dep) {
	if (dep > cnt) return;
	
	if (a[dep-1][1] == m && a[dep-1][2] == n) {
		cnt = min(dep-1,cnt);
		return;
	}
	for (int i=0;i<12;i++) {
		int x,y;
		x=a[dep-1][1]+dx[i];
		y=a[dep-1][2]+dy[i];
		if (x>0  &&  y>0 && x<=m && y<=n) {
			a[dep][1]=x;
			a[dep][2]=y;
			dfs(dep+1);
		}
	}
}

int main() {
	cnt=10000000;
	cin >> m >> n;
	a[0][1]=1;
	a[0][2]=1;
	dfs(1);
	cout << cnt << endl;
	cnt=10000000;
	cin >> m >> n;
	a[0][1]=1;
	a[0][2]=1;
	dfs(1);
	cout << cnt;
	return 0;
}
2024/7/9 17:55
加载中...