Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions mhkim/baekjoon/6603.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* @file 6603.cpp
* @brief 로또
* @author Sam Kim (samkim2626@gmail.com)
*
* 조합(combination)
* kC6 k개 중에서 6개 뽑기
* DFS?
*/
#include <iostream>
#include <vector>

using namespace std;

#define r 6

int k;
int s[13];
int arr[13];

void comb(int start, int depth)
{
if (depth == r)
{
for (int i = 0; i < r; i++)
{
cout << arr[i] << ' ';
}
cout << '\n';
return;
}

for (int i = start; i < k; i++)
{
arr[depth] = s[i];
comb(i + 1, depth + 1);
}
}

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);

while (1)
{
cin >> k;
if (k == 0)
{
break;
}

for (int i = 0; i < k; i++)
{
cin >> s[i];
}

comb(0, 0);

cout << '\n';
}

return 0;
}
81 changes: 81 additions & 0 deletions mhkim/baekjoon/7562.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* @file 7562.cpp
* @brief 나이트의 이동
* @author Sam Kim (samkim2626@gmail.com)
*
* bfs
*
* !! memset - #include <cstring>
*/
#include <iostream>
#include <deque>
#include <utility>
#include <cstring>

using namespace std;

bool chess[300][300];
int l;
pair<int, int> moves[8] = {{-2, -1}, {-1, -2}, {1, -2}, {2, -1}, {-2, 1}, {-1, 2}, {1, 2}, {2, 1}};

int bfs(pair<int, int> &start, pair<int, int> &end)
{
deque<pair<pair<int, int>, int>> q;
int step = 0;
q.push_back(make_pair(start, step));
chess[start.first][start.second] = true;

int count = 0;
while (!q.empty())
{
pair<pair<int, int>, int> qNow = q.front();
pair<int, int> now = qNow.first;
count = qNow.second;
q.pop_front();

if (now.first == end.first && now.second == end.second)
{
break;
}

count += 1;
for (int i = 0; i < 8; i++)
{
if (chess[now.first + moves[i].first][now.second + moves[i].second] != true)
{
if (now.first + moves[i].first > l - 1 || now.first + moves[i].first < 0 || now.second + moves[i].second > l - 1 || now.second + moves[i].second < 0)
{
continue;
}
q.push_back(make_pair(make_pair(now.first + moves[i].first, now.second + moves[i].second), count));
chess[now.first + moves[i].first][now.second + moves[i].second] = true;
}
}
}

return count;
}

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);

int t;
cin >> t;
while (t--)
{
cin >> l;
int fromX, fromY;
cin >> fromX >> fromY;
pair<int, int> from = {fromX, fromY};
int toX, toY;
cin >> toX >> toY;
pair<int, int> to = {toX, toY};

cout << bfs(from, to) << '\n';
memset(chess, false, sizeof(chess));
}

return 0;
}
46 changes: 46 additions & 0 deletions mhkim/greedy-1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @file greedy-1.cpp
* @brief 모험가 길드
* @author Sam Kim (samkim2626@gmail.com)
*
* sort
*
*/
#include <iostream>
#include <algorithm>

using namespace std;

int mo[100001];

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);

int n;
cin >> n;

for (int i = 0; i < n; i++)
{
cin >> mo[i];
}

sort(mo, mo + n);

int nGroup = 0;
int nMo = 0; // 현재 그룹에 포함된 모험가의 수
for (int i = 0; i < n; i++)
{
nMo++;
if (nMo >= mo[i])
{
nGroup++;
nMo = 0;
}
}

cout << nGroup << '\n';

return 0;
}
37 changes: 37 additions & 0 deletions mhkim/greedy-2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @file greedy-2.cpp
* @brief 곱하기 혹은 더하기
* @author Sam Kim (samkim2626@gmail.com)
*/
#include <iostream>

using namespace std;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);

string s;
cin >> s;

int sum = 0;
for (int i = 0; i < s.length(); i++)
{
int n = s[i] - '0';
int hap = sum + n;
int gop = sum * n;
if (hap < gop)
{
sum = gop;
}
else
{
sum = hap;
}
}

cout << sum << '\n';

return 0;
}
34 changes: 34 additions & 0 deletions mhkim/greedy-3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @file greedy-3.cpp
* @brief 문자열 뒤집기
* @author Sam Kim (samkim2626@gmail.com)
*/
#include <iostream>

using namespace std;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);

string s;
cin >> s;

int one2zero, zero2one = 0;
for (int i = 1; i < s.length(); i++)
{
if (s[i - 1] == '0' && s[i - 1] != s[i])
{
zero2one++;
}
else if (s[i - 1] == '1' && s[i - 1] != s[i])
{
one2zero++;
}
}

cout << min(zero2one, one2zero) << '\n';

return 0;
}