T1
傻逼题。
然而我在考试的时候去写dp去了还写了个单调队列优化,怕不是中了bzoj1044的毒。
T2
离散化。田地太大,面积太大,直接搜是不可能的,但是
T3
首先
附上T3代码。
#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define N 1001
#define INF 2100000000
const int dr[] = { 0, 1, 0, -1 };
const int dc[] = { 1, 0, -1, 0 };
inline int read() {
int x = 0, flag = 1; char ch = getchar();
while (ch > '9' || ch < '0') { if (ch == '-') flag = -1; ch = getchar(); }
while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
return x * flag;
}
inline void write(int x) { if (x >= 10) write(x / 10); putchar(x % 10 + '0'); }
int n, x, y;
int xs, ys, xt, yt;
struct enemy { int r, c, dis; };
queue<enemy> q;
bool vis[N][N];
int dis[N][N], d[N][N];
void bfs() {
while (q.size()) {
enemy u = q.front(); q.pop();
if (vis[u.r][u.c]) continue;
vis[u.r][u.c] = 1;
dis[u.r][u.c] = u.dis;
rep(i, 0, 3) {
int nr = u.r + dr[i], nc = u.c + dc[i];
if (nr >= 0 && nr < x && nc >= 0 && nc < y)
q.push(enemy{ nr, nc, u.dis + 1 });
}
}
}
bool check(int k) {
q.push(enemy{ xs, ys, 0 });
while (q.size()) {
enemy u = q.front(); q.pop();
if (vis[u.r][u.c]) continue;
vis[u.r][u.c] = 1;
d[u.r][u.c] = u.dis;
rep(i, 0, 3) {
int nr = u.r + dr[i], nc = u.c + dc[i];
if (nr >= 0 && nr < x && nc >= 0 && nc < y && dis[nr][nc] >= k)
q.push(enemy{ nr, nc, u.dis + 1 });
}
}
return d[xt][yt] != INF;
}
int main() {
scanf("%d%d%d%d%d%d%d", &n, &x, &y, &xs, &ys, &xt, &yt);
rep(i, 1, n) q.push(enemy{ read(), read(), 0 });
bfs();
int l = 0, r = min(dis[xs][ys], dis[xt][yt]);
int ans1, ans2;
while (l <= r) {
memset(vis, 0, sizeof vis);
rep(i, 0, x) rep(j, 0, y) d[i][j] = INF;
int mid = l + r >> 1;
if (check(mid)) ans1 = mid, l = mid + 1, ans2 = d[xt][yt];
else r = mid - 1;
}
printf("%d %d", ans1, ans2);
return 0;
}