From 323b56348145655e865a1e600b73bf8268fcd0d0 Mon Sep 17 00:00:00 2001 From: InSange Date: Tue, 9 Apr 2024 19:45:25 +0900 Subject: [PATCH 1/3] 8-InSange --- InSange/README.md | 3 +- .../2470.cpp" | 96 +++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 "InSange/\355\210\254\355\217\254\354\235\270\355\204\260/2470.cpp" diff --git a/InSange/README.md b/InSange/README.md index b510896..0960f73 100644 --- a/InSange/README.md +++ b/InSange/README.md @@ -8,6 +8,7 @@ | 4차시 | 2024.03.25 | 다익스트라 | [파티](https://www.acmicpc.net/problem/1238) | [#4](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/15)| | 5차시 | 2024.03.27 | DP | [RGB거리2](https://www.acmicpc.net/problem/17404) | [#5](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/19)] | 6차시 | 2024.04.01 | 최소신장트리 | [행성 터널](https://www.acmicpc.net/problem/2887) | [#6](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/24)] -| 7차시 | 2024.04.04 | 스택 | [문자열 폭발](https://www.acmicpc.net/problem/9935) | [#7](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/19)] +| 7차시 | 2024.04.04 | 스택 | [문자열 폭발](https://www.acmicpc.net/problem/9935) | [#7](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/28)] +| 8차시 | 2024.04.09 | 투 포인터 | [두 용액](https://www.acmicpc.net/problem/2470) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/28)] ======= --- diff --git "a/InSange/\355\210\254\355\217\254\354\235\270\355\204\260/2470.cpp" "b/InSange/\355\210\254\355\217\254\354\235\270\355\204\260/2470.cpp" new file mode 100644 index 0000000..dcb049f --- /dev/null +++ "b/InSange/\355\210\254\355\217\254\354\235\270\355\204\260/2470.cpp" @@ -0,0 +1,96 @@ +#include +#include +#include + +using namespace std; + +const int MAX_VAL = 1999999999; + +int N, num, minVal, aanswer, banswer; +vector acid; // 꼺 +vector basic; // ⼺ + +bool cmp(int a, int b) +{ + return a > b; +} + +void Input() +{ + cin >> N; + + for (int i = 0; i < N; i++) + { + cin >> num; + (num > 0) ? acid.push_back(num) : basic.push_back(num); + } + + sort(acid.begin(), acid.end()); + sort(basic.begin(), basic.end(), cmp); + + minVal = MAX_VAL; +} + +void Solve() +{ + int a_index = 0; + int b_index = 0; + while (a_index < acid.size() && b_index < basic.size()) + { + int anum, bnum; + anum = acid[a_index]; + bnum = basic[b_index]; + + if (abs(anum + bnum) < minVal) + { + aanswer = anum; + banswer = bnum; + minVal = abs(anum + bnum); + } + + (abs(anum) > abs(bnum)) ? b_index++ : a_index++; + } + + int sum; + if (acid.size() > 1) + { + sum = abs(acid[0] + acid[1]); + if (sum < minVal) + { + aanswer = acid[1]; + banswer = acid[0]; + } + } + if (basic.size() > 1) + { + sum = abs(basic[0] + basic[1]); + if (sum < minVal) + { + aanswer = basic[0]; + banswer = basic[1]; + } + } + if (acid.empty()) + { + aanswer = basic[0]; + banswer = basic[1]; + } + if (basic.empty()) + { + aanswer = acid[1]; + banswer = acid[0]; + } + + cout << banswer << " " << aanswer; +} + +int main() +{ + cin.tie(nullptr); + ios::sync_with_stdio(false); + + Input(); + Solve(); + + return 0; +} \ No newline at end of file From 57b94ef84b556fd8e0993d76e9211b121e93c697 Mon Sep 17 00:00:00 2001 From: InSange Date: Tue, 9 Apr 2024 19:45:42 +0900 Subject: [PATCH 2/3] Revert "8-InSange" This reverts commit 323b56348145655e865a1e600b73bf8268fcd0d0. --- InSange/README.md | 3 +- .../2470.cpp" | 96 ------------------- 2 files changed, 1 insertion(+), 98 deletions(-) delete mode 100644 "InSange/\355\210\254\355\217\254\354\235\270\355\204\260/2470.cpp" diff --git a/InSange/README.md b/InSange/README.md index 0960f73..b510896 100644 --- a/InSange/README.md +++ b/InSange/README.md @@ -8,7 +8,6 @@ | 4차시 | 2024.03.25 | 다익스트라 | [파티](https://www.acmicpc.net/problem/1238) | [#4](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/15)| | 5차시 | 2024.03.27 | DP | [RGB거리2](https://www.acmicpc.net/problem/17404) | [#5](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/19)] | 6차시 | 2024.04.01 | 최소신장트리 | [행성 터널](https://www.acmicpc.net/problem/2887) | [#6](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/24)] -| 7차시 | 2024.04.04 | 스택 | [문자열 폭발](https://www.acmicpc.net/problem/9935) | [#7](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/28)] -| 8차시 | 2024.04.09 | 투 포인터 | [두 용액](https://www.acmicpc.net/problem/2470) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/28)] +| 7차시 | 2024.04.04 | 스택 | [문자열 폭발](https://www.acmicpc.net/problem/9935) | [#7](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/19)] ======= --- diff --git "a/InSange/\355\210\254\355\217\254\354\235\270\355\204\260/2470.cpp" "b/InSange/\355\210\254\355\217\254\354\235\270\355\204\260/2470.cpp" deleted file mode 100644 index dcb049f..0000000 --- "a/InSange/\355\210\254\355\217\254\354\235\270\355\204\260/2470.cpp" +++ /dev/null @@ -1,96 +0,0 @@ -#include -#include -#include - -using namespace std; - -const int MAX_VAL = 1999999999; - -int N, num, minVal, aanswer, banswer; -vector acid; // 꼺 -vector basic; // ⼺ - -bool cmp(int a, int b) -{ - return a > b; -} - -void Input() -{ - cin >> N; - - for (int i = 0; i < N; i++) - { - cin >> num; - (num > 0) ? acid.push_back(num) : basic.push_back(num); - } - - sort(acid.begin(), acid.end()); - sort(basic.begin(), basic.end(), cmp); - - minVal = MAX_VAL; -} - -void Solve() -{ - int a_index = 0; - int b_index = 0; - while (a_index < acid.size() && b_index < basic.size()) - { - int anum, bnum; - anum = acid[a_index]; - bnum = basic[b_index]; - - if (abs(anum + bnum) < minVal) - { - aanswer = anum; - banswer = bnum; - minVal = abs(anum + bnum); - } - - (abs(anum) > abs(bnum)) ? b_index++ : a_index++; - } - - int sum; - if (acid.size() > 1) - { - sum = abs(acid[0] + acid[1]); - if (sum < minVal) - { - aanswer = acid[1]; - banswer = acid[0]; - } - } - if (basic.size() > 1) - { - sum = abs(basic[0] + basic[1]); - if (sum < minVal) - { - aanswer = basic[0]; - banswer = basic[1]; - } - } - if (acid.empty()) - { - aanswer = basic[0]; - banswer = basic[1]; - } - if (basic.empty()) - { - aanswer = acid[1]; - banswer = acid[0]; - } - - cout << banswer << " " << aanswer; -} - -int main() -{ - cin.tie(nullptr); - ios::sync_with_stdio(false); - - Input(); - Solve(); - - return 0; -} \ No newline at end of file From 894a6a355532e2aa1731cecf685c90936b4e5f44 Mon Sep 17 00:00:00 2001 From: InSange Date: Tue, 9 Apr 2024 19:48:57 +0900 Subject: [PATCH 3/3] =?UTF-8?q?2024-04-09=20=EB=91=90=20=EC=9A=A9=EC=95=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- InSange/README.md | 3 +- .../2470.cpp" | 96 +++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 "InSange/\355\210\254\355\217\254\354\235\270\355\204\260/2470.cpp" diff --git a/InSange/README.md b/InSange/README.md index b510896..0960f73 100644 --- a/InSange/README.md +++ b/InSange/README.md @@ -8,6 +8,7 @@ | 4차시 | 2024.03.25 | 다익스트라 | [파티](https://www.acmicpc.net/problem/1238) | [#4](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/15)| | 5차시 | 2024.03.27 | DP | [RGB거리2](https://www.acmicpc.net/problem/17404) | [#5](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/19)] | 6차시 | 2024.04.01 | 최소신장트리 | [행성 터널](https://www.acmicpc.net/problem/2887) | [#6](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/24)] -| 7차시 | 2024.04.04 | 스택 | [문자열 폭발](https://www.acmicpc.net/problem/9935) | [#7](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/19)] +| 7차시 | 2024.04.04 | 스택 | [문자열 폭발](https://www.acmicpc.net/problem/9935) | [#7](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/28)] +| 8차시 | 2024.04.09 | 투 포인터 | [두 용액](https://www.acmicpc.net/problem/2470) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/28)] ======= --- diff --git "a/InSange/\355\210\254\355\217\254\354\235\270\355\204\260/2470.cpp" "b/InSange/\355\210\254\355\217\254\354\235\270\355\204\260/2470.cpp" new file mode 100644 index 0000000..dcb049f --- /dev/null +++ "b/InSange/\355\210\254\355\217\254\354\235\270\355\204\260/2470.cpp" @@ -0,0 +1,96 @@ +#include +#include +#include + +using namespace std; + +const int MAX_VAL = 1999999999; + +int N, num, minVal, aanswer, banswer; +vector acid; // 꼺 +vector basic; // ⼺ + +bool cmp(int a, int b) +{ + return a > b; +} + +void Input() +{ + cin >> N; + + for (int i = 0; i < N; i++) + { + cin >> num; + (num > 0) ? acid.push_back(num) : basic.push_back(num); + } + + sort(acid.begin(), acid.end()); + sort(basic.begin(), basic.end(), cmp); + + minVal = MAX_VAL; +} + +void Solve() +{ + int a_index = 0; + int b_index = 0; + while (a_index < acid.size() && b_index < basic.size()) + { + int anum, bnum; + anum = acid[a_index]; + bnum = basic[b_index]; + + if (abs(anum + bnum) < minVal) + { + aanswer = anum; + banswer = bnum; + minVal = abs(anum + bnum); + } + + (abs(anum) > abs(bnum)) ? b_index++ : a_index++; + } + + int sum; + if (acid.size() > 1) + { + sum = abs(acid[0] + acid[1]); + if (sum < minVal) + { + aanswer = acid[1]; + banswer = acid[0]; + } + } + if (basic.size() > 1) + { + sum = abs(basic[0] + basic[1]); + if (sum < minVal) + { + aanswer = basic[0]; + banswer = basic[1]; + } + } + if (acid.empty()) + { + aanswer = basic[0]; + banswer = basic[1]; + } + if (basic.empty()) + { + aanswer = acid[1]; + banswer = acid[0]; + } + + cout << banswer << " " << aanswer; +} + +int main() +{ + cin.tie(nullptr); + ios::sync_with_stdio(false); + + Input(); + Solve(); + + return 0; +} \ No newline at end of file