-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 30-xxubin04
- Loading branch information
Showing
11 changed files
with
411 additions
and
3 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
9-kyo-hwang/Brute Force/2024 KAKAO WINTER INTERNSHIP λ¬Έμ 3 μ£Όμ¬μ κ³ λ₯΄κΈ°.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
86 changes: 86 additions & 0 deletions
86
9-kyo-hwang/Prefix Sum/2022 KAKAO BLIND RECRUITMENT νκ΄΄λμ§ μμ 건물.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
Dolchae/λΈλ£¨νΈν¬μ€/2961 λμμ΄κ° λ§λ λ§μλ μμn.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.