1 条题解
-
0
#include <iostream> #include <fstream> #include <cassert> #include <cstdlib> #include <cmath> #include <map> #include <set> #include <algorithm> #include <vector> #include <queue> #include <list> #include <cstring> #define all(x) (x).begin(),(x).end() using namespace std; const int nmax = 1e3; int dxhorse[] = { 0, 0, 0, -1, 1 }; int dyhorse[] = { 0, -1, 1, 0, 0 }; int dx[] = { 0, 0, 0, 1, 1, 1, -1, -1, -1 }; int dy[] = { -1, 0, 1, -1, 0, 1, -1, 0, 1 }; int n,m; int hedgehogX, hedgehogY; int possibleHorseMinX; int possibleHorseMaxX; int possibleHorseMinY; int possibleHorseMaxY; int totalHorseDX; int totalHorseDY; int norm(int dcoord) { if (dcoord > 0) return 1; if (dcoord < 0) return -1; return 0; } void updateX(int& x) { x = min(x, m); x = max(1, x); } void updateY(int& y) { y = min(y, n); y = max(1, y); } void makeHorseMove(int& x, int& y) { int answer, movedx, movedy; scanf("%d%d%d", &answer, &movedx, &movedy); if (answer == 1) exit(0); x += movedx; y += movedy; possibleHorseMinX += movedx; updateX(possibleHorseMinX); possibleHorseMaxX += movedx; updateX(possibleHorseMaxX); possibleHorseMinY += movedy; updateY(possibleHorseMinY); possibleHorseMaxY += movedy; updateY(possibleHorseMaxY); totalHorseDX += movedx; totalHorseDY += movedy; } bool correct(int x, int y) { return 1 <= x && x <= m && 1 <= y && y <= n; } bool correctHorse(int x, int y) { return correct(x, y) && (possibleHorseMinX <= x && x <= possibleHorseMaxX && possibleHorseMinY <= y && y <= possibleHorseMaxY); } void catchHorse(int horseX, int horseY) { horseX += totalHorseDX; horseY += totalHorseDY; bool found = 0; while (!found) { if (!correctHorse(horseX, horseY)) return; int dx = norm(horseX - hedgehogX); int dy = norm(horseY - hedgehogY); hedgehogX += dx; hedgehogY += dy; printf("%d %d %d\n", dx, dy, found = (hedgehogX == horseX && hedgehogY == horseY)); fflush(stdout); makeHorseMove(horseX, horseY); } } int dist(int x1, int y1, int x2, int y2) { return max(abs(x1 - x2), abs(y1 - y2)); } int main() { scanf("%d %d", &n, &m); scanf("%d %d", &hedgehogX, &hedgehogY); possibleHorseMinX = 1; possibleHorseMinY = 1; possibleHorseMaxX = m; possibleHorseMaxY = n; int res = int(1e9); res = min(res, dist(1, 1, hedgehogX, hedgehogY)); res = min(res, dist(1, n, hedgehogX, hedgehogY)); res = min(res, dist(m, 1, hedgehogX, hedgehogY)); res = min(res, dist(m, n, hedgehogX, hedgehogY)); bool dirX = true; bool dirY = true; if (res == dist(1, 1, hedgehogX, hedgehogY)) { dirX = 1; dirY = 1; }; if (res == dist(1, m, hedgehogX, hedgehogY)) { dirX = 1; dirY = 0; }; if (res == dist(n, 1, hedgehogX, hedgehogY)) { dirX = 0; dirY = 1; }; if (res == dist(n, m, hedgehogX, hedgehogY)) { dirX = 0; dirY = 0; }; int xbegin, xend, dx; int ybegin, yend, dy; if (dirX) { xbegin = 1, xend = m, dx = 1; } else { xbegin = m, xend = 1, dx = -1; }; if (dirY) { ybegin = 1, yend = n, dy = 1; } else { ybegin = n, yend = 1, dy = -1; }; for (int i = xbegin; i != xend + dx; i += dx) if (i % 2 == 1) { for (int j = ybegin; j != yend + dy; j += dy) catchHorse(i, j); } else { for (int j = yend; j != ybegin - dy; j -= dy) catchHorse(i, j); } assert(false); return 0; }
- 1
信息
- ID
- 10357
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 1
- 已通过
- 1
- 上传者