Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

13-YIM2UL2ET #42

Merged
merged 5 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions YIM2UL2ET/BFS/13μ°¨μ‹œ - BOJ 7569.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <iostream>
#include <vector>
#include <queue>

struct idx {int z, y, x;};

int main(void)
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);

int m, n, h, res = 0, non = 0;
std::vector <idx> offset = {{1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1}};
std::queue <idx> que[2];
bool curQueue = false;

std::cin >> n >> m >> h;
int box[h][m][n];

for (int z = 0; z < h; z++) {
for (int y = 0; y < m; y++) {
for (int x = 0; x < n; x++) {
std::cin >> box[z][y][x];
if (box[z][y][x] == 1) que[curQueue].push({z, y, x});
else if (box[z][y][x] == 0) non++;
}
}
}

while (!que[curQueue].empty() && non > 0) {
while (!que[curQueue].empty()) {
int z = que[curQueue].front().z, y = que[curQueue].front().y, x = que[curQueue].front().x;
for (idx set : offset) {
int zz = z + set.z, yy = y + set.y, xx = x + set.x;
if (zz >= 0 && zz < h && yy >= 0 && yy < m && xx >= 0 && xx < n && box[zz][yy][xx] == 0) {
box[zz][yy][xx] = 1, non--;
que[!curQueue].push({zz, yy, xx});
}
}
que[curQueue].pop();
}
curQueue = !curQueue;
res++;
}

if (non > 0) std::cout << -1;
else std::cout << res;

return 0;
}
3 changes: 3 additions & 0 deletions YIM2UL2ET/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@
| 08μ°¨μ‹œ | 2024.03.04 | μž¬κ·€ | [BOJ 10994](https://www.acmicpc.net/problem/10994) | [BOJ 10994 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/27) |
| 09μ°¨μ‹œ | 2024.03.07 | μž„μ˜ 정밀도 / 큰 수 μ—°μ‚° && μž¬κ·€ | [BOJ 1914](https://www.acmicpc.net/problem/1914) | [BOJ 1914 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/29) |
| 10μ°¨μ‹œ | 2024.03.10 | μŠ€νƒ | [BOJ 1406](https://www.acmicpc.net/problem/1406) | [BOJ 1406 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/31) |
| 11μ°¨μ‹œ | 2024.03.18 | μŠ€νƒ | [BOJ 1918](https://www.acmicpc.net/problem/1918) | [BOJ 1918 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/36) |
| 12μ°¨μ‹œ | 2024.03.28 | λΉ„νŠΈλ§ˆμŠ€ν‚Ή | [BOJ 11723](https://www.acmicpc.net/problem/11723) | [BOJ 11723 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/39) |
| 13μ°¨μ‹œ | 2024.04.01 | BFS | [BOJ 7569](https://www.acmicpc.net/problem/7569) | [BOJ 7569 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/42) |
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <iostream>

int main(void)
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);

int n, k, bits = 0;
std::string command;

std::cin >> n;
for (int i = 0; i < n; i++) {
std::cin >> command;
if (command == "add") {
std::cin >> k;
bits |= (1<<k);
}
else if (command == "remove") {
std::cin >> k;
bits &= ~(1<<k);
}
else if (command == "check") {
std::cin >> k;
if (bits & (1<<k)) std::cout << "1\n";
else std::cout << "0\n";
}
else if (command == "toggle") {
std::cin >> k;
bits ^= (1<<k);
}
else if (command == "all") bits = (1<<21)-1;
else bits = 0;
}
return 0;
}
43 changes: 43 additions & 0 deletions YIM2UL2ET/μŠ€νƒ/11μ°¨μ‹œ - BOJ 1918.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <iostream>
#include <stack>

int main(void)
{
char ch;
std::stack <char> stk;
std::string res;

ch = getchar();
while (ch != '\n') {
if (ch == '+' || ch == '-') {
while(!stk.empty() && stk.top() != '(') {
res.push_back(stk.top());
stk.pop();
}
stk.push(ch);
}
else if (ch == '*' || ch == '/') {
if (!stk.empty() && (stk.top() == '*' || stk.top() == '/')) {
res.push_back(stk.top());
stk.pop();
}
stk.push(ch);
}
else if (ch == ')') {
while (!stk.empty() && stk.top() != '(') {
res.push_back(stk.top());
stk.pop();
}
if (!stk.empty()) stk.pop();
}
else if (ch == '(') stk.push(ch);
else res.push_back(ch);
ch = getchar();
}
while (!stk.empty()) {
res.push_back(stk.top());
stk.pop();
}
std::cout << res;
return 0;
}