From 4281f49d3f072dda13c75558830ac590b05e5942 Mon Sep 17 00:00:00 2001 From: 9kyo-hwang Date: Thu, 30 May 2024 21:36:18 +0900 Subject: [PATCH 1/7] 51-9kyo-hwang --- ...234\354\212\244\355\205\234 Version 2.cpp" | 179 ++++++++++++++++++ 9-kyo-hwang/README.md | 3 +- 2 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 "9-kyo-hwang/Data Structure/21944 \353\254\270\354\240\234 \354\266\224\354\262\234 \354\213\234\354\212\244\355\205\234 Version 2.cpp" diff --git "a/9-kyo-hwang/Data Structure/21944 \353\254\270\354\240\234 \354\266\224\354\262\234 \354\213\234\354\212\244\355\205\234 Version 2.cpp" "b/9-kyo-hwang/Data Structure/21944 \353\254\270\354\240\234 \354\266\224\354\262\234 \354\213\234\354\212\244\355\205\234 Version 2.cpp" new file mode 100644 index 0000000..a4016dd --- /dev/null +++ "b/9-kyo-hwang/Data Structure/21944 \353\254\270\354\240\234 \354\266\224\354\262\234 \354\213\234\354\212\244\355\205\234 Version 2.cpp" @@ -0,0 +1,179 @@ +#include +#include + +using namespace std; + +class Database +{ +public: + int Recommend1(int G, int x) + { + if(x == 1) + { + return Recommend1P(G); + } + else if(x == -1) + { + return Recommend1N(G); + } + } + + int Recommend2(int x) + { + if(x == 1) + { + return Recommend2P(); + } + else if(x == -1) + { + return Recommend2N(); + } + } + + int Recommend3(int x, int L) + { + if(x == 1) + { + return Recommend3P(L); + } + else if(x == -1) + { + return Recommend3N(L); + } + } + + void Add(int P, int L, int G) + { + ProblemByLevel[L].emplace(P); + ProblemByLevelAndGroup[L][G].emplace(P); + Problems[P] = {L, G}; + } + + void Solved(int P) + { + ProblemByLevel[Problems[P].first].erase(P); + ProblemByLevelAndGroup[Problems[P].first][Problems[P].second].erase(P); + } + +private: + set ProblemByLevel[101]; + set ProblemByLevelAndGroup[101][101]; + pair Problems[100001]; + + int Recommend1P(int G) + { + for(int L = 100; L >= 1; --L) + { + if(!ProblemByLevelAndGroup[L][G].empty()) + { + return *(--ProblemByLevelAndGroup[L][G].end()); + } + } + } + + int Recommend1N(int G) + { + for(int L = 1; L <= 100; ++L) + { + if(!ProblemByLevelAndGroup[L][G].empty()) + { + return *ProblemByLevelAndGroup[L][G].begin(); + } + } + } + + int Recommend2P() + { + for(int L = 100; L >= 1; --L) + { + if(!ProblemByLevel[L].empty()) + { + return *(--ProblemByLevel[L].end()); + } + } + } + + int Recommend2N() + { + for(int L = 1; L <= 100; ++L) + { + if(!ProblemByLevel[L].empty()) + { + return *ProblemByLevel[L].begin(); + } + } + } + + int Recommend3P(int L) + { + for(; L <= 100; ++L) + { + if(!ProblemByLevel[L].empty()) + { + return *ProblemByLevel[L].begin(); + } + } + return -1; + } + + int Recommend3N(int L) + { + for(L -= 1; L >= 1; --L) + { + if(!ProblemByLevel[L].empty()) + { + return *(--ProblemByLevel[L].end()); + } + } + return -1; + } +}; + +int main() +{ + cin.tie(nullptr)->sync_with_stdio(false); + + Database* DB = new Database(); + + int N; cin >> N; + while(N--) + { + int P, L, G; cin >> P >> L >> G; + DB->Add(P, L, G); + } + + int M; cin >> M; + while(M--) + { + string Command; cin >> Command; + if(Command == "recommend") // find Max/Min in Category G + { + int G, x; cin >> G >> x; + cout << DB->Recommend1(G, x) << "\n"; + } + else if(Command == "recommend2") // find Max/Min any Category + { + int x; cin >> x; + cout << DB->Recommend2(x) << "\n"; + } + else if(Command == "recommend3") // find lower bound + { + int x, L; cin >> x >> L; + cout << DB->Recommend3(x, L) << "\n"; + } + else if(Command == "add") + { + int P, L, G; cin >> P >> L >> G; + DB->Add(P, L, G); + } + else if(Command == "solved") + { + int P; cin >> P; + DB->Solved(P); + } + } + + delete DB; + + return 0; +} \ No newline at end of file diff --git a/9-kyo-hwang/README.md b/9-kyo-hwang/README.md index 02f8857..14aac20 100644 --- a/9-kyo-hwang/README.md +++ b/9-kyo-hwang/README.md @@ -50,4 +50,5 @@ | 47차시 | 2024.5.16 | Brute Force | [14500 테트로미노](https://www.acmicpc.net/problem/14503) | [#171](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/171) | | 48차시 | 2024.5.20 | Shortest Path | [1162 도로포장](https://www.acmicpc.net/problem/1162) | [#175](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/175) | | 49차시 | 2024.5.23 | Data Structure | [21939 문제 추천 시스템 Version 1](https://www.acmicpc.net/problem/21939) | [#179](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/179) | -| 50차시 | 2024.5.25 | Graph Traversal | [26146 즉흥 여행 (Easy)](https://www.acmicpc.net/problem/26146) | [#182](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/182) | \ No newline at end of file +| 50차시 | 2024.5.25 | Graph Traversal | [26146 즉흥 여행 (Easy)](https://www.acmicpc.net/problem/26146) | [#182](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/182) | +| 51차시 | 2024.5.30 | Data Structure | [21944 문제 추천 시스템 Version 2](https://www.acmicpc.net/problem/21944) | [#185](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/185) | \ No newline at end of file From a665e5eba4aeee3696b0cbc49c15154c6792d113 Mon Sep 17 00:00:00 2001 From: 9kyo-hwang Date: Mon, 3 Jun 2024 16:41:22 +0900 Subject: [PATCH 2/7] 52-9kyo-hwang --- ... \355\233\204\353\263\264\355\202\244.cpp" | 58 +++++++++++++++++++ 9-kyo-hwang/README.md | 3 +- 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 "9-kyo-hwang/Data Structure/2019 KAKAO BLIND RECRUITMENT \355\233\204\353\263\264\355\202\244.cpp" diff --git "a/9-kyo-hwang/Data Structure/2019 KAKAO BLIND RECRUITMENT \355\233\204\353\263\264\355\202\244.cpp" "b/9-kyo-hwang/Data Structure/2019 KAKAO BLIND RECRUITMENT \355\233\204\353\263\264\355\202\244.cpp" new file mode 100644 index 0000000..db24c9f --- /dev/null +++ "b/9-kyo-hwang/Data Structure/2019 KAKAO BLIND RECRUITMENT \355\233\204\353\263\264\355\202\244.cpp" @@ -0,0 +1,58 @@ +#include +#include +#include + +using namespace std; + +bool IsUnique(const vector>& Relation, const int RowSize, const int ColSize, int AttributeSet) +{ + vector Columns; + for(int Column = 0; Column < ColSize; ++Column) + { + if((AttributeSet >> Column) & 1) + { + Columns.emplace_back(Column); + } + } + + unordered_set Set; + for(int Row = 0; Row < RowSize; ++Row) + { + string Attributes{}; + for(int Column : Columns) + { + Attributes += Relation[Row][Column]; + } + Set.emplace(Attributes); + } + + return Set.size() == RowSize; +} + +bool IsMinimal(const vector& CandidateKeys, int AttributeSet) +{ + for(int CandidateKey : CandidateKeys) + { + if((AttributeSet & CandidateKey) == CandidateKey) + { + return false; + } + } + return true; +} + +int solution(vector> Relation) +{ + const size_t RowSize = Relation.size(), ColSize = Relation.front().size(); + vector CandidateKeys; + + for(int AttributeSet = 1; AttributeSet < (1 << ColSize); ++AttributeSet) + { + if(!IsMinimal(CandidateKeys, AttributeSet)) continue; + if(!IsUnique(Relation, RowSize, ColSize, AttributeSet)) continue; + + CandidateKeys.emplace_back(AttributeSet); + } + + return CandidateKeys.size(); +} \ No newline at end of file diff --git a/9-kyo-hwang/README.md b/9-kyo-hwang/README.md index 14aac20..70c6136 100644 --- a/9-kyo-hwang/README.md +++ b/9-kyo-hwang/README.md @@ -51,4 +51,5 @@ | 48차시 | 2024.5.20 | Shortest Path | [1162 도로포장](https://www.acmicpc.net/problem/1162) | [#175](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/175) | | 49차시 | 2024.5.23 | Data Structure | [21939 문제 추천 시스템 Version 1](https://www.acmicpc.net/problem/21939) | [#179](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/179) | | 50차시 | 2024.5.25 | Graph Traversal | [26146 즉흥 여행 (Easy)](https://www.acmicpc.net/problem/26146) | [#182](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/182) | -| 51차시 | 2024.5.30 | Data Structure | [21944 문제 추천 시스템 Version 2](https://www.acmicpc.net/problem/21944) | [#185](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/185) | \ No newline at end of file +| 51차시 | 2024.5.30 | Data Structure | [21944 문제 추천 시스템 Version 2](https://www.acmicpc.net/problem/21944) | [#185](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/185) | +| 52차시 | 2024.6.03 | Data Structure | [2019 KAKAO BLIND RECRUITMENT 후보키](https://school.programmers.co.kr/learn/courses/30/lessons/42890?language=cpp) | [#187](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/187) | \ No newline at end of file From 1b534f164e40779eb20df6812b8911147961db15 Mon Sep 17 00:00:00 2001 From: 9kyo-hwang Date: Mon, 1 Jul 2024 01:39:58 +0900 Subject: [PATCH 3/7] 53-9kyo-hwang --- ... \354\202\254\354\235\264\355\201\264.cpp" | 75 +++++++++++++++++++ 9-kyo-hwang/README.md | 3 +- 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 "9-kyo-hwang/Graph Traversal/\354\233\224\352\260\204 \354\275\224\353\223\234 \354\261\214\353\246\260\354\247\200 \354\213\234\354\246\214 3 - \353\271\233\354\235\230 \352\262\275\353\241\234 \354\202\254\354\235\264\355\201\264.cpp" diff --git "a/9-kyo-hwang/Graph Traversal/\354\233\224\352\260\204 \354\275\224\353\223\234 \354\261\214\353\246\260\354\247\200 \354\213\234\354\246\214 3 - \353\271\233\354\235\230 \352\262\275\353\241\234 \354\202\254\354\235\264\355\201\264.cpp" "b/9-kyo-hwang/Graph Traversal/\354\233\224\352\260\204 \354\275\224\353\223\234 \354\261\214\353\246\260\354\247\200 \354\213\234\354\246\214 3 - \353\271\233\354\235\230 \352\262\275\353\241\234 \354\202\254\354\235\264\355\201\264.cpp" new file mode 100644 index 0000000..1924aa8 --- /dev/null +++ "b/9-kyo-hwang/Graph Traversal/\354\233\224\352\260\204 \354\275\224\353\223\234 \354\261\214\353\246\260\354\247\200 \354\213\234\354\246\214 3 - \353\271\233\354\235\230 \352\262\275\353\241\234 \354\202\254\354\235\264\355\201\264.cpp" @@ -0,0 +1,75 @@ +#include +#include +#include + +using namespace std; + +const vector> Offset{{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; + +size_t N, M; +vector>> Visited; // (x, y, dir) + +inline void Compensation(int& Val, int MinVal, int MaxVal) +{ + if(Val < MinVal) Val = MaxVal; + else if(Val > MaxVal) Val = 0; +} + +int DFS(const vector& Grid, int x, int y, int d, int CycleLength = 1) +{ + Visited[x][y][d] = true; + + int nd; + switch(Grid[x][y]) + { + case 'S': + nd = d; + break; + case 'L': + nd = d - 1; + Compensation(nd, 0, 3); + break; + case 'R': + nd = d + 1; + Compensation(nd, 0, 3); + break; + } + + const auto& [dx, dy] = Offset[nd]; + int nx = x + dx, ny = y + dy; + Compensation(nx, 0, N - 1), Compensation(ny, 0, M - 1); + + if(Visited[nx][ny][nd]) + { + return CycleLength; + } + else + { + return DFS(Grid, nx, ny, nd, CycleLength + 1); + } +} + +vector solution(vector Grid) +{ + N = Grid.size(), M = Grid[0].size(); + Visited.assign(N, vector(M, vector(4, false))); + + vector Answer; + for(int x = 0; x < N; ++x) + { + for(int y = 0; y < M; ++y) + { + for(int d = 0; d < 4; ++d) + { + if(!Visited[x][y][d]) + { + Answer.emplace_back(DFS(Grid, x, y, d)); + } + } + } + } + + sort(Answer.begin(), Answer.end()); + + return Answer; +} \ No newline at end of file diff --git a/9-kyo-hwang/README.md b/9-kyo-hwang/README.md index 70c6136..1bc7d06 100644 --- a/9-kyo-hwang/README.md +++ b/9-kyo-hwang/README.md @@ -52,4 +52,5 @@ | 49차시 | 2024.5.23 | Data Structure | [21939 문제 추천 시스템 Version 1](https://www.acmicpc.net/problem/21939) | [#179](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/179) | | 50차시 | 2024.5.25 | Graph Traversal | [26146 즉흥 여행 (Easy)](https://www.acmicpc.net/problem/26146) | [#182](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/182) | | 51차시 | 2024.5.30 | Data Structure | [21944 문제 추천 시스템 Version 2](https://www.acmicpc.net/problem/21944) | [#185](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/185) | -| 52차시 | 2024.6.03 | Data Structure | [2019 KAKAO BLIND RECRUITMENT 후보키](https://school.programmers.co.kr/learn/courses/30/lessons/42890?language=cpp) | [#187](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/187) | \ No newline at end of file +| 52차시 | 2024.6.03 | Data Structure | [2019 KAKAO BLIND RECRUITMENT 후보키](https://school.programmers.co.kr/learn/courses/30/lessons/42890) | [#187](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/187) | +| 53차시 | 2024.6.03 | Graph Traversal | [월간 코드 챌린지 시즌3 빛의 경로 사이클](https://school.programmers.co.kr/learn/courses/30/lessons/86052) | [#193](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/193)ㄴ | \ No newline at end of file From a1c66855435c9faefdfddad8f634ec369c9a65f7 Mon Sep 17 00:00:00 2001 From: 9kyo-hwang Date: Mon, 1 Jul 2024 02:08:59 +0900 Subject: [PATCH 4/7] =?UTF-8?q?[Fix]=20README.md=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=88=98=EC=A0=95(=EC=9E=98=EB=AA=BB=EB=90=9C=20=EB=82=A0?= =?UTF-8?q?=EC=A7=9C=20=EB=B0=8F=20=EC=98=A4=ED=83=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 9-kyo-hwang/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/9-kyo-hwang/README.md b/9-kyo-hwang/README.md index 1bc7d06..f857b0d 100644 --- a/9-kyo-hwang/README.md +++ b/9-kyo-hwang/README.md @@ -53,4 +53,4 @@ | 50차시 | 2024.5.25 | Graph Traversal | [26146 즉흥 여행 (Easy)](https://www.acmicpc.net/problem/26146) | [#182](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/182) | | 51차시 | 2024.5.30 | Data Structure | [21944 문제 추천 시스템 Version 2](https://www.acmicpc.net/problem/21944) | [#185](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/185) | | 52차시 | 2024.6.03 | Data Structure | [2019 KAKAO BLIND RECRUITMENT 후보키](https://school.programmers.co.kr/learn/courses/30/lessons/42890) | [#187](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/187) | -| 53차시 | 2024.6.03 | Graph Traversal | [월간 코드 챌린지 시즌3 빛의 경로 사이클](https://school.programmers.co.kr/learn/courses/30/lessons/86052) | [#193](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/193)ㄴ | \ No newline at end of file +| 53차시 | 2024.7.01 | Graph Traversal | [월간 코드 챌린지 시즌3 빛의 경로 사이클](https://school.programmers.co.kr/learn/courses/30/lessons/86052) | [#193](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/193) | \ No newline at end of file From 22b3eace18c6453aa24248b35bb8668a3bea3775 Mon Sep 17 00:00:00 2001 From: 9kyo-hwang Date: Fri, 5 Jul 2024 00:08:08 +0900 Subject: [PATCH 5/7] 54-9kyo-hwang --- ... \353\213\211\353\204\244\354\236\204.cpp" | 47 +++++++++++++++++++ 9-kyo-hwang/README.md | 3 +- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 "9-kyo-hwang/Data Structure/16934 \352\262\214\354\236\204 \353\213\211\353\204\244\354\236\204.cpp" diff --git "a/9-kyo-hwang/Data Structure/16934 \352\262\214\354\236\204 \353\213\211\353\204\244\354\236\204.cpp" "b/9-kyo-hwang/Data Structure/16934 \352\262\214\354\236\204 \353\213\211\353\204\244\354\236\204.cpp" new file mode 100644 index 0000000..4145512 --- /dev/null +++ "b/9-kyo-hwang/Data Structure/16934 \352\262\214\354\236\204 \353\213\211\353\204\244\354\236\204.cpp" @@ -0,0 +1,47 @@ +#include +#include +#include +#include + +using namespace std; + +int main() +{ + cin.tie(nullptr)->sync_with_stdio(false); + + unordered_set Storage; + unordered_map NicknameMap; + + int N; cin >> N; + while(N--) + { + string Nickname; cin >> Nickname; + NicknameMap[Nickname]++; + + bool bEmplaced = false; + string Prefix{}; + for(const char& ch : Nickname) + { + Prefix += ch; + if(Storage.count(Prefix) == 0 && !bEmplaced) + { + cout << Prefix << "\n"; + bEmplaced = true; + } + Storage.emplace(Prefix); + } + + if(!bEmplaced) + { + string Prefix = Nickname; + if(NicknameMap[Nickname] > 1) + { + Prefix += to_string(NicknameMap[Nickname]); + } + Storage.emplace(Prefix); + cout << Prefix << "\n"; + } + } + + return 0; +} \ No newline at end of file diff --git a/9-kyo-hwang/README.md b/9-kyo-hwang/README.md index f857b0d..61c0129 100644 --- a/9-kyo-hwang/README.md +++ b/9-kyo-hwang/README.md @@ -53,4 +53,5 @@ | 50차시 | 2024.5.25 | Graph Traversal | [26146 즉흥 여행 (Easy)](https://www.acmicpc.net/problem/26146) | [#182](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/182) | | 51차시 | 2024.5.30 | Data Structure | [21944 문제 추천 시스템 Version 2](https://www.acmicpc.net/problem/21944) | [#185](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/185) | | 52차시 | 2024.6.03 | Data Structure | [2019 KAKAO BLIND RECRUITMENT 후보키](https://school.programmers.co.kr/learn/courses/30/lessons/42890) | [#187](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/187) | -| 53차시 | 2024.7.01 | Graph Traversal | [월간 코드 챌린지 시즌3 빛의 경로 사이클](https://school.programmers.co.kr/learn/courses/30/lessons/86052) | [#193](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/193) | \ No newline at end of file +| 53차시 | 2024.7.01 | Graph Traversal | [월간 코드 챌린지 시즌3 빛의 경로 사이클](https://school.programmers.co.kr/learn/courses/30/lessons/86052) | [#193](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/193) | +| 54차시 | 2024.7.04 | Data Structure | [16934 게임 닉네임](https://www.acmicpc.net/problem/16934) | [#197](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/197) | \ No newline at end of file From 92c35f20e6bed1e51383d2060ae3de474f979e8a Mon Sep 17 00:00:00 2001 From: 9kyo-hwang Date: Tue, 9 Jul 2024 20:52:38 +0900 Subject: [PATCH 6/7] 55-9kyo-hwang --- 9-kyo-hwang/README.md | 3 +- ...354\247\200 \354\225\210\353\205\225!.cpp" | 127 ++++++++++++++++++ 2 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 "9-kyo-hwang/Simulation/17144 \353\257\270\354\204\270\353\250\274\354\247\200 \354\225\210\353\205\225!.cpp" diff --git a/9-kyo-hwang/README.md b/9-kyo-hwang/README.md index 61c0129..4518bd4 100644 --- a/9-kyo-hwang/README.md +++ b/9-kyo-hwang/README.md @@ -54,4 +54,5 @@ | 51차시 | 2024.5.30 | Data Structure | [21944 문제 추천 시스템 Version 2](https://www.acmicpc.net/problem/21944) | [#185](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/185) | | 52차시 | 2024.6.03 | Data Structure | [2019 KAKAO BLIND RECRUITMENT 후보키](https://school.programmers.co.kr/learn/courses/30/lessons/42890) | [#187](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/187) | | 53차시 | 2024.7.01 | Graph Traversal | [월간 코드 챌린지 시즌3 빛의 경로 사이클](https://school.programmers.co.kr/learn/courses/30/lessons/86052) | [#193](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/193) | -| 54차시 | 2024.7.04 | Data Structure | [16934 게임 닉네임](https://www.acmicpc.net/problem/16934) | [#197](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/197) | \ No newline at end of file +| 54차시 | 2024.7.04 | Data Structure | [16934 게임 닉네임](https://www.acmicpc.net/problem/16934) | [#197](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/197) | +| 55차시 | 2024.7.09 | Simulation | [17144 미세먼지 안녕!](https://www.acmicpc.net/problem/16934) | [#202](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/202) | \ No newline at end of file diff --git "a/9-kyo-hwang/Simulation/17144 \353\257\270\354\204\270\353\250\274\354\247\200 \354\225\210\353\205\225!.cpp" "b/9-kyo-hwang/Simulation/17144 \353\257\270\354\204\270\353\250\274\354\247\200 \354\225\210\353\205\225!.cpp" new file mode 100644 index 0000000..2a21141 --- /dev/null +++ "b/9-kyo-hwang/Simulation/17144 \353\257\270\354\204\270\353\250\274\354\247\200 \354\225\210\353\205\225!.cpp" @@ -0,0 +1,127 @@ +#include +#include + +using namespace std; + +const vector> Offset{{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; + +enum EHouse +{ + AirPurifier = -1, + Empty = 0 +}; + +int R, C, T; +vector> A; +vector> Modifier; +vector AirPurifierPos; + +inline bool OutOfBound(int r, int c) +{ + return r < 0 || r >= R || c < 0 || c >= C; +} + +void Diffusion(int r, int c) +{ + int AmountofDiffusion = A[r][c] / 5; + int NumofDirDiffusion = 0; + + for(const auto& [dr, dc] : Offset) + { + int nr = r + dr, nc = c + dc; + if(!OutOfBound(nr, nc) && A[nr][nc] != EHouse::AirPurifier) + { + Modifier[nr][nc] += AmountofDiffusion; + NumofDirDiffusion++; + } + } + + Modifier[r][c] -= AmountofDiffusion * NumofDirDiffusion; +} + +void DiffusionParticulateMatter() +{ + for(int r = 0; r < R; ++r) + { + for(int c = 0; c < C; ++c) + { + if(A[r][c] != EHouse::AirPurifier && A[r][c] != EHouse::Empty) + { + Diffusion(r, c); + } + } + } + + for(int r = 0; r < R; ++r) + { + for(int c = 0; c < C; ++c) + { + A[r][c] += Modifier[r][c]; + Modifier[r][c] = 0; + } + } +} + +void WorkAirPurifier() +{ + { + int r = AirPurifierPos[0]; + for(int i = r - 1; i > 0; --i) A[i][0] = A[i - 1][0]; // to N + for(int j = 0; j < C - 1; ++j) A[0][j] = A[0][j + 1]; // to E + for(int i = 0; i < r; ++i) A[i][C - 1] = A[i + 1][C - 1]; // to S + for(int j = C - 1; j > 1; --j) A[r][j] = A[r][j - 1]; // to W + A[r][1] = 0; + } + { + int r = AirPurifierPos[1]; + for(int i = r + 1; i < R - 1; ++i) A[i][0] = A[i + 1][0]; // to S + for(int j = 0; j < C - 1; ++j) A[R - 1][j] = A[R - 1][j + 1]; // to E + for(int i = R - 1; i > r; --i) A[i][C - 1] = A[i - 1][C - 1]; // to N + for(int j = C - 1; j > 1; --j) A[r][j] = A[r][j - 1]; // to W + A[r][1] = 0; + } +} + + +int main() +{ + cin.tie(nullptr)->sync_with_stdio(false); + + cin >> R >> C >> T; + A.assign(R, vector(C, 0)); + Modifier.assign(R, vector(C, 0)); + + for(int r = 0; r < R; ++r) + { + for(int c = 0; c < C; ++c) + { + cin >> A[r][c]; + if(A[r][c] == EHouse::AirPurifier) + { + AirPurifierPos.emplace_back(r); + } + } + } + + while(T--) + { + DiffusionParticulateMatter(); + WorkAirPurifier(); + } + + int Answer = 0; + for(int r = 0; r < R; ++r) + { + for(int c = 0; c < C; ++c) + { + if(A[r][c] > 0) + { + Answer += A[r][c]; + } + } + } + + cout << Answer; + + return 0; +} \ No newline at end of file From 0945df5d76af8008202a6b4acb3e08d54ec1d6f0 Mon Sep 17 00:00:00 2001 From: 9kyo-hwang Date: Fri, 12 Jul 2024 11:32:40 +0900 Subject: [PATCH 7/7] 56-9kyo-hwang --- 9-kyo-hwang/README.md | 3 +- ...\354\231\200 \354\277\274\353\246\254.cpp" | 49 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 "9-kyo-hwang/Tree/15681 \355\212\270\353\246\254\354\231\200 \354\277\274\353\246\254.cpp" diff --git a/9-kyo-hwang/README.md b/9-kyo-hwang/README.md index 4518bd4..c34cdad 100644 --- a/9-kyo-hwang/README.md +++ b/9-kyo-hwang/README.md @@ -55,4 +55,5 @@ | 52차시 | 2024.6.03 | Data Structure | [2019 KAKAO BLIND RECRUITMENT 후보키](https://school.programmers.co.kr/learn/courses/30/lessons/42890) | [#187](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/187) | | 53차시 | 2024.7.01 | Graph Traversal | [월간 코드 챌린지 시즌3 빛의 경로 사이클](https://school.programmers.co.kr/learn/courses/30/lessons/86052) | [#193](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/193) | | 54차시 | 2024.7.04 | Data Structure | [16934 게임 닉네임](https://www.acmicpc.net/problem/16934) | [#197](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/197) | -| 55차시 | 2024.7.09 | Simulation | [17144 미세먼지 안녕!](https://www.acmicpc.net/problem/16934) | [#202](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/202) | \ No newline at end of file +| 55차시 | 2024.7.09 | Simulation | [17144 미세먼지 안녕!](https://www.acmicpc.net/problem/16934) | [#202](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/202) | +| 56차시 | 2024.7.12 | Tree | [15681 트리와 쿼리](https://www.acmicpc.net/problem/15681) | [#204](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/204) | \ No newline at end of file diff --git "a/9-kyo-hwang/Tree/15681 \355\212\270\353\246\254\354\231\200 \354\277\274\353\246\254.cpp" "b/9-kyo-hwang/Tree/15681 \355\212\270\353\246\254\354\231\200 \354\277\274\353\246\254.cpp" new file mode 100644 index 0000000..cd416f1 --- /dev/null +++ "b/9-kyo-hwang/Tree/15681 \355\212\270\353\246\254\354\231\200 \354\277\274\353\246\254.cpp" @@ -0,0 +1,49 @@ +#include +#include +#include + +using namespace std; + +int main() +{ + cin.tie(nullptr)->sync_with_stdio(false); + + int N, R, Q; cin >> N >> R >> Q; + vector> Tree(N + 1); + for(int i = 0; i < N - 1; ++i) + { + int U, V; cin >> U >> V; + Tree[U].emplace_back(V); + Tree[V].emplace_back(U); + } + + vector Size(N + 1, 1); + vector Visited(N + 1, false); + + function DFS = [&](int Parent) + { + if(Visited[Parent]) + { + return Size[Parent]; + } + + Visited[Parent] = true; + for(const int Child : Tree[Parent]) + { + if(!Visited[Child]) + { + Size[Parent] += DFS(Child); + } + } + + return Size[Parent]; + }; DFS(R); + + while(Q--) + { + int U; cin >> U; + cout << Size[U] << "\n"; + } + + return 0; +} \ No newline at end of file