From 45386830b6666948d2881148ced396f0e989c501 Mon Sep 17 00:00:00 2001 From: Suhyeon <70002218+onpyeong@users.noreply.github.com> Date: Tue, 29 Apr 2025 21:07:59 +0900 Subject: [PATCH 1/5] =?UTF-8?q?=EB=AF=B8=EC=84=B8=EB=A8=BC=EC=A7=80=5F?= =?UTF-8?q?=EC=95=88=EB=85=95!=5F17144.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 09/kang/17144.cpp | 119 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 09/kang/17144.cpp diff --git a/09/kang/17144.cpp b/09/kang/17144.cpp new file mode 100644 index 0000000..4bebc04 --- /dev/null +++ b/09/kang/17144.cpp @@ -0,0 +1,119 @@ +#include +#include +#include +#include +using namespace std; + +int R, C, T; +int map[51][51]; +int temp[51][51]; +int d[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; +int machine_up_r; +int machine_down_r; + +void spreadDust() { + memset(temp, 0, sizeof(temp)); + queue> q; + int x, y, nx, ny, dCnt; + + for(int i = 0; i < R; i++) { + for(int j = 0; j < C; j++) { + if(map[i][j] != 0) { + q.push({i, j}); + temp[i][j] = map[i][j]; + } + } + } + + while(!q.empty()) { + x = q.front().first; + y = q.front().second; + q.pop(); + dCnt = 0; + for(int i = 0; i < 4; i++) { + nx = x + d[i][0]; + ny = y + d[i][1]; + if(nx < 0 || nx >= R || ny < 0 || ny >= C) + continue; + if(map[nx][ny] == -1) + continue; + temp[nx][ny] += floor(map[x][y] / 5); + dCnt++; + } + temp[x][y] -= floor(map[x][y] / 5) * dCnt; + } + + for(int i = 0; i < R; i++) { + for(int j = 0; j < C; j++) { + map[i][j] = temp[i][j]; + } + } +} + +void runMachine() { + //위쪽 공기청정기 + for(int r = machine_up_r - 1; r > 0; r--) { + map[r][0] = map[r - 1][0]; + } + for(int c = 1; c < C; c++) { + map[0][c - 1] = map[0][c]; + } + for(int r = 1; r <= machine_up_r; r++) { + map[r - 1][C - 1] = map[r][C - 1]; + } + for(int c = C - 2; c >= 1; c--) { + map[machine_up_r][c + 1] = map[machine_up_r][c]; + } + map[machine_up_r][1] = 0; + + //아래쪽 공기청정기 + for(int r = machine_down_r + 2; r < R; r++) { + map[r - 1][0] = map[r][0]; + } + for(int c = 1; c < C; c++) { + map[R - 1][c - 1] = map[R - 1][c]; + } + for(int r = R - 2; r >= machine_down_r; r--) { + map[r + 1][C - 1] = map[r][C - 1]; + } + for(int c = C - 2; c >= 1; c--) { + map[machine_down_r][c + 1] = map[machine_down_r][c]; + } + map[machine_down_r][1] = 0; +} + +int calcDust() { + int cnt = 0; + for(int i = 0; i < R; i++) { + for(int j = 0; j < C; j++) { + if(map[i][j] > 0) { + cnt += map[i][j]; + } + } + } + return cnt; +} + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + cin >> R >> C >> T; + for(int i = 0; i < R; i++) { + for(int j = 0; j < C; j++) { + cin >> map[i][j]; + if(map[i][j] == -1) { + if(machine_up_r == 0) + machine_up_r = i; + else + machine_down_r = i; + } + } + } + + while(T--) { + spreadDust(); + runMachine(); + } + cout << calcDust(); +} From 35d1ff10432f07549d1ecd8a9479d482dc79c65c Mon Sep 17 00:00:00 2001 From: Suhyeon <70002218+onpyeong@users.noreply.github.com> Date: Wed, 30 Apr 2025 23:21:11 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=EB=B1=80=EA=B3=BC=5F=EC=82=AC=EB=8B=A4?= =?UTF-8?q?=EB=A6=AC=5F=EA=B2=8C=EC=9E=84=5F16928.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 문제 접근에 주의 - dp는 사이클이 생기면 안됨! - 완탐에서 최단거리? -> BFS - **주사위를 굴려 이동한 칸**이 뱀 또는 사다리이면 타고 이동함 - 즉, 주사위를 굴려서 사다리인 칸에 도착했는데, 해당 칸에 또 사다리가 있어도 이동하지 않음! - 그러면 우선 6번의 주사위를 굴리면서 방문하지 않았는데, 사다리 또는 뱀이면 무조건 타야하므로 도착한 좌표로 변환하고 그 좌표를 큐에 넣어준다! --- 09/kang/16928.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 09/kang/16928.cpp diff --git a/09/kang/16928.cpp b/09/kang/16928.cpp new file mode 100644 index 0000000..8fe965d --- /dev/null +++ b/09/kang/16928.cpp @@ -0,0 +1,56 @@ +#include +#include +using namespace std; + +int N, M; +int ladder[103]; +int snake[103]; +bool visit[103]; + +int bfs() { + queue> q; //좌표, 주사위 수 + int x, cnt, nx; + + q.push({1, 0}); + visit[1] = true; + while(!q.empty()) { + x = q.front().first; + cnt = q.front().second; + q.pop(); + if(x == 100) { + return cnt; + } + for(int i = 1; i <= 6; i++) { + nx = x + i; + if(nx > 100) + break; + if(visit[nx]) + continue; + if(ladder[nx] != 0) //사다리를 타고 이동한 좌표 + nx = ladder[nx]; + if(snake[nx] != 0) //뱀으로 이동한 좌표 + nx = snake[nx]; + q.push({nx, cnt + 1}); + visit[nx] = true; + } + } + +} + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + int idx; + + cin >> N >> M; + for(int i = 0; i < N; i++) { + cin >> idx >> ladder[idx]; + } + for(int i = 0; i < M; i++) { + cin >> idx >> snake[idx]; + } + + cout << bfs() << "\n"; + + return 0; +} From 14a2ccf331e36abe0e46b36edb474e35d0e9344f Mon Sep 17 00:00:00 2001 From: Suhyeon <70002218+onpyeong@users.noreply.github.com> Date: Thu, 1 May 2025 20:12:54 +0900 Subject: [PATCH 3/5] =?UTF-8?q?=EA=B3=BC=EC=9D=BC=5F=ED=83=95=ED=9B=84?= =?UTF-8?q?=EB=A3=A8=5F30804.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 투 포인터로 해결 가능 - right를 하나씩 증가시키면서 과일을 보고 - map[과일 종류]++; 를 증가시킴 - map.size가 2보다 크면 - while(map.size() > 2) // 2가지 종류가 될 때까지 left를 증가시킴 - map[left]--; - 개수가 0이면 과일을 제거 - left++; - 과일 개수 갱신! (r - l + 1) --- 09/kang/30804.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 09/kang/30804.cpp diff --git a/09/kang/30804.cpp b/09/kang/30804.cpp new file mode 100644 index 0000000..62d94b2 --- /dev/null +++ b/09/kang/30804.cpp @@ -0,0 +1,50 @@ +#include +#include + +using namespace std; + +int N; +int s[200003]; +int f[2]; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + cin >> N; + for(int i = 0; i < N; i++) { + cin >> s[i]; + } + + int maxCnt = 1; + int cnt = 0; + for(int i = 0; i < N; i++) { + bool isFind = false; + for(int j = 0; j < 2; j++) { //과일이 있는지 판단 + if(s[i] == f[j]) { + isFind = true; + cnt++; + break; + } + } + if(!isFind) { //새로운 과일이면 + maxCnt = max(maxCnt, cnt); + + int j = i - 1; + int bCnt = 0; + int bf = i - 1 >= 0 ? s[i - 1] : 0; + while(j >= 0 && s[j] == bf) { + bCnt++; + j--; + } + + cnt = bCnt + 1; //이전 과일 개수 + 새로운 과일 개수(1) + f[0] = bf; + f[1] = s[i]; + } + } + maxCnt = max(maxCnt, cnt); + cout << maxCnt << "\n"; + + return 0; +} From 9ead747107215ddb520358e3cf63bb9f90e87bab Mon Sep 17 00:00:00 2001 From: Suhyeon <70002218+onpyeong@users.noreply.github.com> Date: Fri, 2 May 2025 17:38:48 +0900 Subject: [PATCH 4/5] =?UTF-8?q?=EC=BC=80=EB=B9=88=5F=EB=B2=A0=EC=9D=B4?= =?UTF-8?q?=EC=BB=A8=EC=9D=98=5F6=EB=8B=A8=EA=B3=84=5F=EB=B2=95=EC=B9=99?= =?UTF-8?q?=5F1389.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 09/kang/1389.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 09/kang/1389.cpp diff --git a/09/kang/1389.cpp b/09/kang/1389.cpp new file mode 100644 index 0000000..2a39c77 --- /dev/null +++ b/09/kang/1389.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +#include + +using namespace std; + +int N, M; +vector adj[103]; +int dist[103]; +vector> kb; + +int bfs(int s) { + queue q; + int x, sum = 0; + + fill(dist, dist + N + 1, 1e9); + q.push(s); + dist[s] = 1; + while(!q.empty()) { + x = q.front(); + q.pop(); + for(int nxt : adj[x]) { + if(dist[nxt] > dist[x] + 1) { + dist[nxt] = dist[x] + 1; + q.push(nxt); + } + } + } + + for(int i = 1; i <= N; i++) { + sum += dist[i]; + } + return sum; +} + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + int a, b; + + cin >> N >> M; + for(int i = 0; i < M; i++) { + cin >> a >> b; + adj[a].push_back(b); + adj[b].push_back(a); + } + + + for(int i = 1; i <= N; i++) { + kb.push_back({bfs(i), i}); + } + + sort(kb.begin(), kb.end()); + + cout << kb[0].second << "\n"; + + return 0; +} From b769c4d8ebcc05485e8394817632e19878bc76c3 Mon Sep 17 00:00:00 2001 From: Suhyeon <70002218+onpyeong@users.noreply.github.com> Date: Wed, 7 May 2025 00:17:23 +0900 Subject: [PATCH 5/5] =?UTF-8?q?=EC=8B=A0=EC=9E=85=5F=EC=82=AC=EC=9B=90=5F1?= =?UTF-8?q?946.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit <조건> 다른 모든 지원자와 비교했을 때 서류심사 성적과 면접시험 성적 중 적어도 하나가 다른 지원자보다 떨어지지 않는 자만 선발한다 - 서류, 면접이 순위가 작은 순으로 정렬 - 서류 순위가 작은(높은)순으로 보면 (이미 한 성적은 떨어짐) 면접 순위가 temp보다 작거나 같으면 (면접에 대해 순위가 높으면) 뽑힘 (temp값을 갱신) --- 09/kang/1946.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 09/kang/1946.cpp diff --git a/09/kang/1946.cpp b/09/kang/1946.cpp new file mode 100644 index 0000000..8de15fb --- /dev/null +++ b/09/kang/1946.cpp @@ -0,0 +1,37 @@ +#include +#include +#include + +using namespace std; + +int main() { + int t, n; + int ans = 0, temp_min; + + cin >> t; + while (t > 0) { + cin >> n; + + ans = 0; + temp_min = n; + vector > rank(n); + + for (int i = 0; i < n; i++) { + cin >> rank[i].first >> rank[i].second; + } + + sort(rank.begin(), rank.end()); + + for (int i = 0; i < n; i++) { + if (rank[i].second <= temp_min) { + ans++; + temp_min = rank[i].second; + } + } + + cout << ans << "\n"; + + t--; + } + +}