Ruby @Sprout2022
解題 SOP
NEOJ 987 - 大十字
NEOJ 938 - 3D迷宮
解題 SOP
NEOJ 987 - 大十字
NEOJ 938 - 3D迷宮
閱讀題目時,留意:
解題 SOP
NEOJ 987 - 大十字
NEOJ 938 - 3D迷宮
\(\text{Let }S\text{ the set of numbers that}\)
\(\text{sit on the cross of }(r, c)\text{ in }M_{m\times n}\)
\(S=\{M_{ij}\}\text{, where}i, j\in N\text{ must satisfy}\)
Write Code!
#include <iostream>
using namespace std;
int main() {
/* Reading input */
int m, n, target, nums[100][100];
cin >> m >> n;
for (int i = 0; i < m; ++i)
for (int j = 0; j < n; ++j)
cin >> nums[i][j];
cin >> target;
/* Finding (r, c) of the target */
int r, c;
for (int i = 0; i < m; ++i) {
bool found = false;
for (int j = 0; j < n; ++j)
if (nums[i][j] == target) {
r = i, c = j, found = true;
break;
}
if (found) break;
}
/* Finding the max. among the numbers of those who have to stand up */
int maxNum = 0;
for (int i = 0; i < m; ++i) // column
if (i != r) maxNum = max(maxNum, nums[i][c]);
for (int j = 0; j < m; ++j) // row
if (j != c) maxNum = max(maxNum, nums[r][j]);
cout << maxNum << '\n';
return 0;
}
解題 SOP
NEOJ 987 - 大十字
NEOJ 938 - 3D迷宮
Ooops!!!
(續上頁)
Write Code!
#include <iostream>
using namespace std;
bool isWall[100][100][100];
char input[1000001];
int main() {
int x, y, z, q, w, e, m;
cin >> x >> y >> z;
cin >> input;
int n = x*y*z;
for (int i = 0; i < n; ++i)
isWall[i % x][(i/x) % y][i / (x*y)] = static_cast<bool>(input[i] - '0');
cin >> q >> w >> e >> m;
for (int i = 0; i < m; ++i) {
int k, newX = q, newY = w, newZ = e;
cin >> k;
if (k == 1) ++newX;
else if (k == 2) --newX;
else if (k == 3) --newY;
else if (k == 4) ++newY;
else if (k == 5) ++newZ;
else if (k == 6) --newZ;
// cout << "(" << newX << "," << newY << "," << newZ << ")" << endl;
if (newX < 0 || newX >= x || newY < 0 || newY >= y || newZ < 0 || newZ >= z || isWall[newX][newY][newZ]) {
cout << "Ooops!!!" << endl;
continue;
}
q = newX, w = newY, e = newZ;
}
cout << q << " " << w << " " << e << endl;
}
Thank you!
Ruby @Sprout 2022