@zoom站长,自测对了,提交错误

tctm169 我以逍遥醉人间 2024-06-22 8:31:04 4

#include <bits/stdc++.h> #include #include #include #include #include #include #include #include using namespace std; int maze[305][305]; bool reach[305][305]; int dx[4] = { -1, 1, 0, 0 }; int dy[4] = { 0, 0, -1, 1 }; int n; struct point { int x, y; point(int a, int b) : x(a), y(b) {} }; bool canreach(int t) { if (maze[0][0] > t) return false; memset(reach, 0, sizeof(reach)); reach[0][0] = 1; queue myqueues; myqueues.push(point(0, 0)); while (!myqueues.empty()) { point top = myqueues.front(); myqueues.pop(); if (top.x == n - 1 && top.y == n - 1) return true; for (int i = 0; i < 4; i++) { int tx = top.x + dx[i]; int ty = top.y + dy[i]; if (tx < 0 || tx >= n || ty < 0 || tx >= n) continue; if (reach[tx][ty]) continue; if (maze[tx][ty] > t) continue; reach[tx][ty] = 1; myqueues.push(point(tx, ty)); } } return false; } int main() { memset(maze, 0, sizeof(maze)); cin >> n; int L = 10000000, R = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> maze[i][j]; L = min(maze[i][j], L); R = max(maze[i][j], R); } } int result = 100000000; while (L <= R) { int mid = (L + R) / 2; if (canreach(mid)) { R = mid - 1; result = min(result, mid); } else { L = mid + 1; } } cout << result; }

{{ vote && vote.total.up }}

共 5 条回复

root 站长

不客气

tctm169 我以逍遥醉人间

谢谢站长,我全对了

tctm169 我以逍遥醉人间

谢谢站长,我全对了

root 站长

windows 环境下对越界判断不严格,所以数据正确,但是评测机环境为 linux,对内存访问很严格(ccf的评测环境也是linux)

root 站长

两个细节错误:

1if (tx < 0 || tx >= n || ty < 0 || tx >= n) 应该是 if (tx < 0 || tx >= n || ty < 0 || ty >= n) 
2if (maze[tx][tx] > t) 应该是 if (maze[tx][ty] > t)

注意细节!!!