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
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing