Skip to content

Commit

Permalink
28-9kyo-hwang
Browse files Browse the repository at this point in the history
  • Loading branch information
9kyo-hwang committed Feb 19, 2024
1 parent b37c842 commit dab9462
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 1 deletion.
55 changes: 55 additions & 0 deletions 9-kyo-hwang/Graph Traversal/1039 ๊ตํ™˜.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <iostream>
#include <string>
#include <algorithm>
#include <unordered_set>

using namespace std;

string N; int K;
unordered_set<int> Visited[11];

int DFS(string Num = N, int Depth = 0)
{
if(Visited[Depth].find(stoi(Num)) != Visited[Depth].end())
{
return -1;
}
else if(Depth == K)
{
return stoi(Num);
}
else
{
Visited[Depth].emplace(stoi(Num));

int MaxNum = -1;
for(int i = 0; i < N.size() - 1; ++i)
{
for(int j = i + 1; j < N.size(); ++j)
{
if(i == 0 && Num[j] == '0')
{
continue;
}

string TmpNum = Num;
swap(TmpNum[i], TmpNum[j]);

MaxNum = max(MaxNum, DFS(TmpNum, Depth + 1));
}
}

return MaxNum;
}
}

int main()
{
cin.tie(nullptr)->sync_with_stdio(false);

cin >> N >> K;

cout << DFS();

return 0;
}
4 changes: 3 additions & 1 deletion 9-kyo-hwang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@
| 23์ฐจ์‹œ | 2024.1.24 | Disjoint Set | [ํ‘œ ๋ณ‘ํ•ฉ](https://school.programmers.co.kr/learn/courses/30/lessons/150366) | [#81](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/81) |
| 24์ฐจ์‹œ | 2024.1.28 | Tree | [ํ‘œํ˜„ ๊ฐ€๋Šฅํ•œ ์ด์ง„ํŠธ๋ฆฌ](https://school.programmers.co.kr/learn/courses/30/lessons/150367) | [#92](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/92) |
| 25์ฐจ์‹œ | 2024.2.8 | Brute Force | [์กฐ์ด์Šคํ‹ฑ](https://school.programmers.co.kr/learn/courses/30/lessons/42860) | [#99](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/99) |
| 26์ฐจ์‹œ | 2024.2.11 | Brute Force | [์ฃผ์‚ฌ์œ„ ๊ณ ๋ฅด๊ธฐ](https://school.programmers.co.kr/learn/courses/30/lessons/258709) | [#104](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/104) |
| 26์ฐจ์‹œ | 2024.2.11 | Brute Force | [์ฃผ์‚ฌ์œ„ ๊ณ ๋ฅด๊ธฐ](https://school.programmers.co.kr/learn/courses/30/lessons/258709) | [#104](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/104) |
| 27์ฐจ์‹œ | 2024.2.14 | Graph Traversal | [1039 ๊ตํ™˜](https://www.acmicpc.net/problem/1039) | [#105](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/105) |
| 28์ฐจ์‹œ | 2024.2.19 | Simulation | [SWEA 5644 ๋ฌด์„  ์ถฉ์ „](https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWXRDL1aeugDFAUo&categoryId=AWXRDL1aeugDFAUo&categoryType=CODE&problemTitle=5644&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=&pageSize=10&pageIndex=1) | [#111](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/111) |
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#include <iostream>
#include <vector>

using namespace std;
using Loc = pair<int, int>;

#define x first
#define y second

Loc operator+(const Loc &a, const Loc &b) { return {a.x + b.x, a.y + b.y}; }

struct BC {
int Index, X, Y, C, P;

BC() : Index(-1), X(-1), Y(-1), C(-1), P(-1) {}
BC(int inIndex, int inX, int inY, int inC, int inP)
: Index(inIndex), X(inX), Y(inY), C(inC), P(inP) {}

[[nodiscard]] inline int D(const Loc &loc) const {
return abs(X - loc.x) + abs(Y - loc.y);
}
};

int main() {
cin.tie(nullptr)->sync_with_stdio(false);
const vector<Loc> offset = {{}, {-1, 0}, {0, 1}, {1, 0}, {0, -1}};

int M, A;
vector<int> aMvTrajectories, bMvTrajectories;
vector<BC> BCs;
Loc aLoc, bLoc;

auto Input = [&]() {
cin >> M >> A;
aMvTrajectories.assign(M + 1, 0);
bMvTrajectories.assign(M + 1, 0);
BCs.assign(A, {});

for (int T = 1; T <= M; ++T) {
cin >> aMvTrajectories[T];
}
for (int T = 1; T <= M; ++T) {
cin >> bMvTrajectories[T];
}

int bcCnt = 0;
for (auto &[Index, X, Y, C, P] : BCs) {
cin >> Y >> X >> C >> P;
Index = bcCnt++;
}

aLoc = {1, 1};
bLoc = {10, 10};
};

auto Charge = [&]() {
int maxCharge = 0;
for (const auto &aBC : BCs) {
const int aDist = aBC.D(aLoc);
const int aAmt = aDist <= aBC.C ? aBC.P : 0;

for (const auto &bBC : BCs) {
const int bDist = bBC.D(bLoc);
const int bAmt = bDist <= bBC.C ? bBC.P : 0;

const int curCharge =
(aBC.Index != bBC.Index ? aAmt + bAmt : max(aAmt, bAmt));

maxCharge = max(maxCharge, curCharge);
}
}
return maxCharge;
};

auto Move = [&]() {
int totalCharge = 0;
for (int time = 0; time <= M; ++time) {
aLoc = aLoc + offset[aMvTrajectories[time]];
bLoc = bLoc + offset[bMvTrajectories[time]];

totalCharge += Charge();
}
return totalCharge;
};

int T;
cin >> T;
for (int tc = 1; tc <= T; ++tc) {
Input();
cout << "#" << tc << " " << Move() << "\n";
}

return 0;
}

0 comments on commit dab9462

Please sign in to comment.