Skip to content

Commit

Permalink
Merge branch 'main' into 30-xxubin04
Browse files Browse the repository at this point in the history
  • Loading branch information
xxubin04 authored Feb 26, 2024
2 parents c6da6a5 + 94cbc2d commit 0026d40
Show file tree
Hide file tree
Showing 11 changed files with 411 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

void CountEachComboSums(const vector<vector<int>>& Dices, const vector<int>& SelectedDices, unordered_map<int, int>& DiceComboMap, int ComboSum = 0, int DiceIndex = 0)
{
if(DiceIndex == SelectedDices.size())
{
DiceComboMap[ComboSum] += 1;
return;
}

for(const int& DicePip : Dices[SelectedDices[DiceIndex]])
{
CountEachComboSums(Dices, SelectedDices, DiceComboMap, ComboSum + DicePip, DiceIndex + 1);
}
}

vector<int> solution(vector<vector<int>> Dice)
{
const int NumDice = Dice.size();
vector<bool> IsADice(NumDice / 2, false);
IsADice.insert(IsADice.end(), NumDice / 2, true);

int MaxCntOfAWins = 0;
vector<int> Answer;
do
{
vector<int> A, B;
for(int i = 0; i < NumDice; ++i)
{
IsADice[i] ? A.emplace_back(i) : B.emplace_back(i);
}

unordered_map<int, int> AComboMap, BComboMap;
CountEachComboSums(Dice, A, AComboMap);
CountEachComboSums(Dice, B, BComboMap);

vector<pair<int, int>> AComboVector(AComboMap.begin(), AComboMap.end());
vector<pair<int, int>> BComboVector(BComboMap.begin(), BComboMap.end());

sort(AComboVector.begin(), AComboVector.end());
sort(BComboVector.begin(), BComboVector.end());

int CntOfAWins = 0;
for(const auto& [AComboSum, AComboCnt] : AComboVector)
{
for(const auto& [BComboSum, BComboCnt] : BComboVector)
{
if(BComboSum >= AComboSum)
{
break;
}

CntOfAWins += AComboCnt * BComboCnt;
}
}

if(CntOfAWins > MaxCntOfAWins)
{
MaxCntOfAWins = CntOfAWins;
Answer = A;
}
} while(next_permutation(IsADice.begin(), IsADice.end()));

transform(Answer.begin(), Answer.end(), Answer.begin(), [](int& i) { return i + 1; });
return Answer;
}
49 changes: 49 additions & 0 deletions 9-kyo-hwang/Graph Traversal/1039 κ΅ν™˜.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include <string>
#include <vector>

using namespace std;

struct FSkill
{
int Type, R1, C1, R2, C2, Degree;

FSkill(const vector<int>& InSkill) : Type(InSkill[0]), R1(InSkill[1]), C1(InSkill[2]), R2(InSkill[3]), C2(InSkill[4]), Degree(InSkill[5]) { }
};

enum class ESkillType
{
NONE,
ATTACK,
HEAL,
};

vector<vector<int>> GetWeightMatrix(const int N, const int M, const vector<vector<int>>& InSkills)
{
vector WeightMatrix(N + 1, vector(M + 1, 0));
for(const vector<int>& InSkill : InSkills)
{
FSkill Skill(InSkill);
if(Skill.Type == static_cast<int>(ESkillType::ATTACK))
{
WeightMatrix[Skill.R1][Skill.C1] -= Skill.Degree;
WeightMatrix[Skill.R2 + 1][Skill.C2 + 1] -= Skill.Degree;

WeightMatrix[Skill.R1][Skill.C2 + 1] += Skill.Degree;
WeightMatrix[Skill.R2 + 1][Skill.C1] += Skill.Degree;
}
else if(Skill.Type == static_cast<int>(ESkillType::HEAL))
{
WeightMatrix[Skill.R1][Skill.C1] += Skill.Degree;
WeightMatrix[Skill.R2 + 1][Skill.C2 + 1] += Skill.Degree;

WeightMatrix[Skill.R1][Skill.C2 + 1] -= Skill.Degree;
WeightMatrix[Skill.R2 + 1][Skill.C1] -= Skill.Degree;
}
}

for(int i = 0; i <= N; ++i)
{
for(int j = 0; j < M; ++j)
{
WeightMatrix[i][j + 1] += WeightMatrix[i][j];
}
}

for(int j = 0; j <= M; ++j)
{
for(int i = 0; i < N; ++i)
{
WeightMatrix[i + 1][j] += WeightMatrix[i][j];
}
}

return WeightMatrix;
}

int solution(vector<vector<int>> Board, vector<vector<int>> Skills)
{
const int N = Board.size(), M = Board[0].size();
vector<vector<int>> WeightMatrix = GetWeightMatrix(N, M, Skills);

for(int i = 0; i < N; ++i)
{
for(int j = 0; j < M; ++j)
{
Board[i][j] += WeightMatrix[i][j];
}
}

int Answer = 0;
for(const vector<int>& Row : Board)
{
for(const int& Col : Row)
{
Answer += (Col > 0);
}
}

return Answer;
}
5 changes: 4 additions & 1 deletion 9-kyo-hwang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@
| 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) |
| 29μ°¨μ‹œ | 2024.2.22 | Prefix Sum | [νŒŒκ΄΄λ˜μ§€ μ•Šμ€ 건물](https://school.programmers.co.kr/learn/courses/30/lessons/92344) | [#114](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/114) |
94 changes: 94 additions & 0 deletions 9-kyo-hwang/Simulation/SWEA 5644 무선 μΆ©μ „.cpp
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;
}
28 changes: 28 additions & 0 deletions Dolchae/DFS&BFS/2644 μ΄Œμˆ˜κ³„μ‚°.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
n = int(input())
a,b = map(int, input().split())
node_num = int(input())
graph = [[] for _ in range(n+1)]
visited = [False] * (n+1)
result = []

for _ in range(node_num):
x, y = map(int, input().split())
graph[x].append(y)
graph[y].append(x)

def dfs(v, num):
num += 1
visited[v] = True

if v == b:
result.append(num)

for i in graph[v]:
if not visited[i]:
dfs(i, num)

dfs(a, 0)
if len(result) == 0:
print(-1)
else:
print(result[0]-1)
5 changes: 4 additions & 1 deletion Dolchae/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@
| 24μ°¨μ‹œ| 2024.01.29 | μˆ˜ν•™ | [2108 톡계학](https://www.acmicpc.net/problem/2108) | [#87](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/87) |
| 25μ°¨μ‹œ| 2024.02.01 | DP | [1535 μ•ˆλ…•](https://www.acmicpc.net/problem/1535) | [#89](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/89) |
| 26μ°¨μ‹œ| 2024.02.05 | κ΅¬ν˜„ | [18110 solved.ac](https://www.acmicpc.net/problem/18110) | [#93](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/93) |
| 27μ°¨μ‹œ| 2024.02.08 | μ •λ ¬ | [1302 λ² μŠ€νŠΈμ…€λŸ¬](https://www.acmicpc.net/problem/1302) | [#97](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/97) |
| 27μ°¨μ‹œ| 2024.02.08 | μ •λ ¬ | [1302 λ² μŠ€νŠΈμ…€λŸ¬](https://www.acmicpc.net/problem/1302) | [#97](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/97) |
| 28μ°¨μ‹œ| 2024.02.15 | 이진 탐색 | [6236 용돈 관리](https://www.acmicpc.net/problem/1302) | [#107](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/107) |
| 29μ°¨μ‹œ| 2024.02.19 | 브루트포슀 | [2961 λ„μ˜μ΄κ°€ λ§Œλ“  λ§›μžˆλŠ” μŒμ‹](https://www.acmicpc.net/problem/2961) | [#109](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/109) |
| 30μ°¨μ‹œ| 2024.02.22 | DFS | [2644 μ΄Œμˆ˜κ³„μ‚°](https://www.acmicpc.net/problem/2961) | [#112](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/112) |
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import sys
from itertools import combinations
input = sys.stdin.readline

n = int(input())

ingrid = [[0 for _ in range(2)] for _ in range(n)]
for i in range(n):
ingrid[i][0],ingrid[i][1] = map(int,input().split())

ans = abs(ingrid[0][0] - ingrid[0][1])
for i in range(1,n+1): #1
for comb in combinations(ingrid,i): #2
print(comb)
sour, bitter = 1,0
for j in range(i): #3
sour *= comb[j][0]
bitter += comb[j][1]
now_diff = abs(sour-bitter)
if now_diff < ans:
ans = now_diff

print(ans)
Loading

0 comments on commit 0026d40

Please sign in to comment.