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

18-YIM2UL2ET #55

Merged
merged 6 commits into from
Jun 27, 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;
}
20 changes: 20 additions & 0 deletions YIM2UL2ET/DP/17์ฐจ์‹œ - BOJ11726.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <iostream>
#include <vector>

std::vector <int> dp(1000);

int func(int n) {
if (dp[n-1] == 0) {
dp[n-1] = (func(n-1) + func(n-2)) % 10007;
}
return dp[n-1];
}

int main(void) {
dp[0] = 1, dp[1] = 2;

int n;
std::cin >> n;
std::cout << func(n);
return 0;
}
8 changes: 7 additions & 1 deletion YIM2UL2ET/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@
| 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) |
| 14์ฐจ์‹œ | 2024.04.04 | ์šฐ์„ ์ˆœ์œ„ ํ | [BOJ 11286](https://www.acmicpc.net/problem/11286) | [BOJ 11286 ํ’€์ด](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/43) |
| 15์ฐจ์‹œ | 2024.04.09 | ๊ตฌํ˜„ | [BOJ 14719](https://www.acmicpc.net/problem/14719) | [BOJ 14719 ํ’€์ด](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/48) |
| 16์ฐจ์‹œ | 2024.04.11 | ์• ๋“œ ํ˜น | [BOJ 15927](https://www.acmicpc.net/problem/15927) | [BOJ 15927 ํ’€์ด](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/51) |
| 17์ฐจ์‹œ | 2024.04.15 | DP | [BOJ 11726](https://www.acmicpc.net/problem/11726) | [BOJ 11726 ํ’€์ด](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/53) |
| 18์ฐจ์‹œ | 2024.04.15 | ํŠธ๋ฆฌ | [BOJ 5639](https://www.acmicpc.net/problem/5639) | [BOJ 5639 ํ’€์ด](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/53) |
---
23 changes: 23 additions & 0 deletions YIM2UL2ET/๊ตฌํ˜„/15์ฐจ์‹œ - BOJ 14719.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <iostream>
#include <algorithm>
#include <vector>

int main(void) {
int height, width, res = 0;

std::cin >> height >> width;
std::vector <int> vec(width);
for (int i = 0; i < width; i++) std::cin >> vec[i];

for (int i = height; i >= 0; i--) {
int cnt = std::count_if(vec.begin(), vec.end(), [&i](int v) -> bool {return v>=i;});
if (cnt > 1) {
int front = std::find_if(vec.begin(), vec.end(), [&i](int v) -> bool {return v>=i;}) - vec.begin();
int back = std::find_if(vec.rbegin(), vec.rend(), [&i](int v) -> bool {return v>=i;}) - vec.rbegin();
res += width - back - front - cnt;
}
}

std::cout << res;
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <iostream>
#include <algorithm>

bool isOneChar(std::string str) {
int size = str.size();
for (int i = 1; i < size; i++) {
if (str[i-1] != str[i]) return false;
}
return true;
}

int main(void) {
std::string str, rstr;
std::cin >> str, rstr = str;
std::reverse(rstr.begin(), rstr.end());

if (isOneChar(str)) std::cout << -1;
else if (str == rstr) std::cout << str.size()-1;
else std::cout << str.size();

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <iostream>
#include <vector>

void cre_heap(std::vector <int> &heap, int key) {
int k = heap.size();
heap.push_back(key);
while (k > 1) {
if (abs(heap[k/2]) > abs(heap[k]) || (abs(heap[k/2]) == abs(heap[k]) && heap[k/2] > heap[k])) {
std::swap(heap[k], heap[k/2]);
k /= 2;
}
else break;
}
return;
}

void del_heap(std::vector <int> &heap) {
int k = 1;
heap[1] = heap.back(), heap.pop_back();
while (k * 2 <= heap.size()) {
if (k * 2 + 1 < heap.size() && (abs(heap[k*2+1]) < abs(heap[k*2]) || (abs(heap[k*2+1]) == abs(heap[k*2]) && heap[k*2+1] < heap[k*2])))
k = k*2+1;
else k = k*2;

if (abs(heap[k/2]) > abs(heap[k]) || (abs(heap[k/2]) == abs(heap[k]) && heap[k/2] > heap[k]))
std::swap(heap[k/2], heap[k]);
else break;
}
return;
}

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

int n, k, x;
std::vector <int> abs_heap = {0};

std::cin >> n;
for (int i = 0; i < n; i++) {
std::cin >> x;
if (abs(x) > 0) cre_heap(abs_heap, x);
else if (abs_heap.size() > 1) {
std::cout << abs_heap[1] << '\n';
del_heap(abs_heap);
}
else std::cout << 0 << '\n';
}

}
34 changes: 34 additions & 0 deletions YIM2UL2ET/ํŠธ๋ฆฌ/18์ฐจ์‹œ - BOJ 5639.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <iostream>
using namespace std;

struct node {
int value = -1;
node* right = NULL;
node* left = NULL;
};

void input(node &nd, int n) {
if (nd.value == -1) nd.value = n;
else if (nd.value > n) {
if (nd.left == NULL) nd.left = new node;
input(*nd.left, n);
}
else {
if (nd.right == NULL) nd.right = new node;
input(*nd.right, n);
}
}

void output(node &nd) {
if (nd.left != NULL) output(*nd.left);
if (nd.right != NULL) output(*nd.right);
cout << nd.value << '\n';
}

int main(void) {
int n;
node root;
while (cin >> n) input(root, n);
output(root);
return 0;
}