题解 | 棋盘
棋盘
https://www.nowcoder.com/practice/b8e7884e2cba4646806a90c4a26a65c5
#include <iostream>
#include <vector>
using namespace std;
int main() {
int size;
cin >> size;
vector<vector<int>> map(size, vector<int>(size));
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
cin >> map[i][j];
}
}
int line;
cin >> line;
while (line--) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
x1--; y1--; x2--; y2--; //变成起始为0的位置。
while (x1 <= x2 && y1 <= y2) { //模拟滚动
if (map[x1][y1] == 0) {
++x1;
} else {
++y1;
}
}
//最终查看滚出位置。
if (x1 > x2) {
cout << x2 + 1 << ' ' << y1+1 << endl;
}
if (y1 > y2) {
cout << x1+1 << ' ' << y2+1 << endl;
}
}
return 0;
}
// 64 位输出请用 printf("%lld")
简单来说,注意一下打印滚出位置的变量是否是正确的,其他的就没什么了。


