From 818cea8d32431be83ffef94749d01e13b14521ee Mon Sep 17 00:00:00 2001 From: kseokc Date: Tue, 1 Apr 2025 12:03:29 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[Baekjoon-2151]=20=EA=B1=B0=EC=9A=B8=20?= =?UTF-8?q?=EC=84=A4=EC=B9=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...354\232\270 \354\204\244\354\271\230).cpp" | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 "\352\271\200\354\204\235\354\260\254/week8/2151(\352\261\260\354\232\270 \354\204\244\354\271\230).cpp" diff --git "a/\352\271\200\354\204\235\354\260\254/week8/2151(\352\261\260\354\232\270 \354\204\244\354\271\230).cpp" "b/\352\271\200\354\204\235\354\260\254/week8/2151(\352\261\260\354\232\270 \354\204\244\354\271\230).cpp" new file mode 100644 index 0000000..e1c8f82 --- /dev/null +++ "b/\352\271\200\354\204\235\354\260\254/week8/2151(\352\261\260\354\232\270 \354\204\244\354\271\230).cpp" @@ -0,0 +1,81 @@ +#include +#include +#include + +using namespace std; + +int N; +string arr[51]; +int visit[51][51][4]; +// 거울을 놓을수있는 형태는 2개 밖에 존재하지 않는다. +vector> v; + + +void input() { + cin >> N; + string s; + for (int i = 0; i < N; i++) { + cin >> s; + arr[i] = s; + for (int j = 0; j < s.length(); j++) { + if (s[j] == '#')v.emplace_back(j, i); + } + } +} + +int xn[] = {0, 0, -1, 1}; +int yn[] = {-1, 1, 0, 0}; +// / 경우 : 위->왼, 왼->위, 하->우, 우->하 +// \ 경우 : 상->우, 우->상, 하->좌, 좌->하 + +// 아래랑 왼쪽이 깐부, 위랑 오른쪽이 깐부 +int sol() { + priority_queue>>, vector>>>, greater<> > q; + for (int i = 0; i < 4; i++) { + q.push({0, {i, {v[0].first, v[0].second}}}); + } + while (!q.empty()) { + int x = q.top().second.second.first; + int y = q.top().second.second.second; + int d = q.top().second.first; + int mirror = q.top().first; +// cout << "x : " << x << "/ y : " << y << "/ d : " << d << "/ mirror : " << mirror << '\n'; + if (x == v[1].first && y == v[1].second)return mirror; + q.pop(); + // 상하좌우 순서로 dis배열이 정의 되어있다. + int xx = x + xn[d]; + int yy = y + yn[d]; + if (yy < 0 || xx < 0 || yy >= N || xx >= N)continue; + if (arr[yy][xx] == '*')continue; + q.push({mirror, {d, {xx, yy}}}); + visit[yy][xx][d] = true; + + if (arr[yy][xx] == '!') { // 이경우에는 두가지의 방법이 가능함 + if (d == 0 || d == 1) { + if (!visit[yy][xx][2]) { + q.push({mirror + 1, {2, {xx, yy}}}); + visit[yy][xx][2] = true; + } + if (!visit[yy][xx][3]) { + q.push({mirror + 1, {3, {xx, yy}}}); + visit[yy][xx][3] = true; + } + } else { + if (!visit[yy][xx][0]) { + q.push({mirror + 1, {0, {xx, yy}}}); + visit[yy][xx][0] = true; + } + if (!visit[yy][xx][1]) { + q.push({mirror + 1, {1, {xx, yy}}}); + visit[yy][xx][1] = true; + } + } + } + + } +} + +int main() { + input(); + cout << sol(); +} From 681e55c4f604eb4f318c102da54e0173dd432d4e Mon Sep 17 00:00:00 2001 From: kseokc Date: Tue, 1 Apr 2025 12:41:54 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[Baekjoon-17490]=20=EC=9D=BC=EA=B0=90?= =?UTF-8?q?=ED=98=B8=EC=97=90=20=EB=8B=A4=EB=A6=AC=20=EB=86=93=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\246\254\353\204\243\352\270\260).cpp" | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 "\352\271\200\354\204\235\354\260\254/week8/17490(\354\235\274\352\260\220\355\230\270\354\227\220 \353\213\244\353\246\254\353\204\243\352\270\260).cpp" diff --git "a/\352\271\200\354\204\235\354\260\254/week8/17490(\354\235\274\352\260\220\355\230\270\354\227\220 \353\213\244\353\246\254\353\204\243\352\270\260).cpp" "b/\352\271\200\354\204\235\354\260\254/week8/17490(\354\235\274\352\260\220\355\230\270\354\227\220 \353\213\244\353\246\254\353\204\243\352\270\260).cpp" new file mode 100644 index 0000000..a31b55b --- /dev/null +++ "b/\352\271\200\354\204\235\354\260\254/week8/17490(\354\235\274\352\260\220\355\230\270\354\227\220 \353\213\244\353\246\254\353\204\243\352\270\260).cpp" @@ -0,0 +1,81 @@ +#include +#include +#include +#include + +using namespace std; + +int N, M, a, b, z, cnt; +long long K; +int parent[1000001]; +vector> arr; +priority_queue>, vector>>, greater<>> Q; + +void reset() { + for (int i = 0; i <= N; i++) { + parent[i] = i; + } +} + +int find(int x) { + if (parent[x] == x)return x; + else { + return parent[x] = find(parent[x]); + } +} + +void Union(int x, int y) { + x = find(x); + y = find(y); + if (x == y)return; + parent[y] = x; +} + +int main() { + ios::sync_with_stdio(false); + cin.tie(0); + cout.tie(0); + cin >> N >> M >> K; + reset(); + arr.resize(N+1); + for (int i = 1; i <= N; i++) { + cin >> z; + Q.push({z, {0, i}}); + } + + for (int i = 0; i < M; i++) { + cin >> a >> b; + arr[a].emplace_back(b); + arr[b].emplace_back(a); + } + + for (int i = 1; i <= N; i++) { + if (i == N)Q.push({0, {i, 1}}); + else Q.push({0, {i, i + 1}}); + } + + while (!Q.empty()) { + int x = Q.top().second.first; + int y = Q.top().second.second; + int value = Q.top().first; + Q.pop(); + auto it = find(arr[x].begin(), arr[x].end(), y); + auto it_1 = find(arr[y].begin(), arr[y].end(), x); + if (find(x) == find(y))continue; + if (it != arr[x].end() || it_1 != arr[y].end())continue; + Union(x, y); + cnt++; + K -= value; + } + + if (M == 0 || M == 1) { + cout << "YES"; + } else { + if (K >= 0 && cnt == N) { + cout << "YES"; + } else { + cout << "NO"; + } + } + +} \ No newline at end of file