Untitled
unknown
plain_text
a year ago
1.2 kB
11
Indexable
#include <iostream>
using namespace std;
int a[1001][1001];
int ax[8] = { -1, -1, -1, 0, 1, 1, 1, 0 };
int ay[8] = { -1, 0, 1, 1, 1, 0, -1, -1 };
int main()
{
int tc;
cin >> tc;
for (int t = 0; t < tc; t++)
{
int ans = 0;
int n, x, y;
cin >> n >> x >> y;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
}
}
int check = 1;
while (check) {
int nextX = x, nextY = y, valNext = 9999999;
for (int i = 0; i < 8; i++) {
int xx = x + ax[i];
int yy = y + ay[i];
if (0 <= xx && xx < n && 0 <= yy && yy < n && a[x][y] < a[xx][yy] && a[xx][yy] < valNext) {
nextX = xx;
nextY = yy;
valNext = a[nextX][nextY];
}
}
if (nextX == x && nextY == y) break;
x = nextX;
y = nextY;
ans++;
}
cout << "#" << t + 1 << " " << ans << endl;
}
return 0;
}Editor is loading...
Leave a Comment