diff --git a/mhkim/baekjoon/6603.cpp b/mhkim/baekjoon/6603.cpp new file mode 100644 index 0000000..83f6254 --- /dev/null +++ b/mhkim/baekjoon/6603.cpp @@ -0,0 +1,64 @@ +/** + * @file 6603.cpp + * @brief 로또 + * @author Sam Kim (samkim2626@gmail.com) + * + * 조합(combination) + * kC6 k개 중에서 6개 뽑기 + * DFS? + */ +#include +#include + +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; +} \ No newline at end of file diff --git a/mhkim/baekjoon/7562.cpp b/mhkim/baekjoon/7562.cpp new file mode 100644 index 0000000..324261a --- /dev/null +++ b/mhkim/baekjoon/7562.cpp @@ -0,0 +1,81 @@ +/** + * @file 7562.cpp + * @brief 나이트의 이동 + * @author Sam Kim (samkim2626@gmail.com) + * + * bfs + * + * !! memset - #include + */ +#include +#include +#include +#include + +using namespace std; + +bool chess[300][300]; +int l; +pair moves[8] = {{-2, -1}, {-1, -2}, {1, -2}, {2, -1}, {-2, 1}, {-1, 2}, {1, 2}, {2, 1}}; + +int bfs(pair &start, pair &end) +{ + deque, 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, int> qNow = q.front(); + pair 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 from = {fromX, fromY}; + int toX, toY; + cin >> toX >> toY; + pair to = {toX, toY}; + + cout << bfs(from, to) << '\n'; + memset(chess, false, sizeof(chess)); + } + + return 0; +} \ No newline at end of file diff --git a/mhkim/greedy-1.cpp b/mhkim/greedy-1.cpp new file mode 100644 index 0000000..d26d959 --- /dev/null +++ b/mhkim/greedy-1.cpp @@ -0,0 +1,46 @@ +/** + * @file greedy-1.cpp + * @brief 모험가 길드 + * @author Sam Kim (samkim2626@gmail.com) + * + * sort + * + */ +#include +#include + +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; +} \ No newline at end of file diff --git a/mhkim/greedy-2.cpp b/mhkim/greedy-2.cpp new file mode 100644 index 0000000..ddb0bdc --- /dev/null +++ b/mhkim/greedy-2.cpp @@ -0,0 +1,37 @@ +/** + * @file greedy-2.cpp + * @brief 곱하기 혹은 더하기 + * @author Sam Kim (samkim2626@gmail.com) + */ +#include + +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; +} \ No newline at end of file diff --git a/mhkim/greedy-3.cpp b/mhkim/greedy-3.cpp new file mode 100644 index 0000000..afb5aca --- /dev/null +++ b/mhkim/greedy-3.cpp @@ -0,0 +1,34 @@ +/** + * @file greedy-3.cpp + * @brief 문자열 뒤집기 + * @author Sam Kim (samkim2626@gmail.com) + */ +#include + +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; +} \ No newline at end of file