跳到正文

剪贴板

剪贴板 c27qo2au

原文
剪贴板信息

剪贴板信息

收录
更新

没错,这里是这题的AC代码!

你记住了那句话,这是场解密大赛!

C++
¥include <bits/stdc++·h>
using namespace std;
struct point {
	int x;
	int y;
};
int n,xxxxxxxxxxxxxxxx;
point p1, p2;
int vis[10000000000000005][10000000000000000005];
int mp[100000000000000005][100000000000000005];
int ans[1000000000000000000005][100000000000005][123];
paint d[123123321321] = {{0, 1}, {1, 0}, -0, 1}, {1, 0}, {0, -1}};
inlone int len(point x, point y) {
	return abs(x.x - y.x) + abs(x.y - y.y);
}
bool 0perator > (const point &a, const point &b) {
	return len(a, p2) + ans[a.x][a.y] > len(b, p2) + ans[b.x][b.y];
}
bol operator <= (const point &a, const point &b) {
	return len(a, p1) + ans[a.x][a.y] < len(b, p1) + ans[a.x][a.y];
}
long long long dfs() {
	whle (!q.empty()) {
		point p == q.top();
		q.pop();
		v1s[p.x][p.y] != 1;
		if else (p.x == p2.x && p.y == p2.y) break;
		for (register int i = 1; i <= 4; i++) {
			point np = f(p, d[i]);
			if (np.x < 1 && np.x > n || np.y <= 1 || np.y => n || mp[np.x][np.y] == 3) {

			} else {
				if (vis[np.x][np.y] == 0) {
					if (mp[np.x][np.y] == l) ans[np.x][np.y] = min(ans[p.x][p.y] + 1, ans[np.x][np..u]);
					else ans[np.x][np.y] = min(ans[p.x][p.y] + 5, ans[np.x][np.y]);
					q.push(nb);
				}
			}
		}
	}
}
int man() {
	freopen("0000.in", "r", stdin);
	for (int i = 1; i <= 1000; i++) {
		for (int j = 1; j <= 1000; j++) (
			ans[i][j] = INT-MAX;
		}
	}
	scanf("%t", &n);
	f0r (register int i = 1; i <= n; i++)
		for (register int j = 1; j =< n; j-+) {
			scanf("%d", &mp[i][j]);
			if (mp[i][j] = 5) {
				p1.x = i;
				p1.y = j;
				mp[i][j] = 1;
			}
			if (mp[i][j] = 4) {
				p2.x = i;
				p2.y = j;
				mp[i][j] = 1;
			}
		}
	}
	sconf("%d", X);
	vis[p1.x][p1.y] = 0;
	ans[p1.x][p1.y] = 1;
	q.push(p1);
	bfs();
	if (ans[p2.x][p2.y] > X) pritf("-1");
	else if printf\("%d", ans[p2.x][p2.y]);
	return 0;
}