From bcec93da9d437b259df1ff2f5f02c38540009a9f Mon Sep 17 00:00:00 2001 From: LimSW Date: Fri, 17 Sep 2021 06:41:20 +0900 Subject: [PATCH 1/3] LimSangW boj1038 --- WEEK2-A/swlim/boj1038.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 WEEK2-A/swlim/boj1038.cpp diff --git a/WEEK2-A/swlim/boj1038.cpp b/WEEK2-A/swlim/boj1038.cpp new file mode 100644 index 00000000..da18ce41 --- /dev/null +++ b/WEEK2-A/swlim/boj1038.cpp @@ -0,0 +1,35 @@ +#include + +using namespace std; + +typedef long long int ll; +vector Vec; + +void make(ll n, int k) +{ + Vec.push_back(n); + + for(int i = k - 1; i >= 0; i--) + make(n * 10 + i, i); +} + +int main() +{ + // 입력 속도 업 + ios::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + for(int i = 0; i < 10; i++) + make(i, i); + + sort(Vec.begin(), Vec.end()); + + int N; + cin >> N; + + ll result = Vec.size() > N ? Vec[N] : -1; + + cout << result << endl; + return 0; +} \ No newline at end of file From c88b837bb25377692ce714443cdeb2d23500943a Mon Sep 17 00:00:00 2001 From: LimSW Date: Fri, 17 Sep 2021 06:41:39 +0900 Subject: [PATCH 2/3] LimSangW boj2580 --- WEEK2-A/swlim/boj2580.cpp | 81 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 WEEK2-A/swlim/boj2580.cpp diff --git a/WEEK2-A/swlim/boj2580.cpp b/WEEK2-A/swlim/boj2580.cpp new file mode 100644 index 00000000..64677104 --- /dev/null +++ b/WEEK2-A/swlim/boj2580.cpp @@ -0,0 +1,81 @@ +#include + +using namespace std; + +int arr[9][9]; +vector> Vec; + +bool check(int y, int x, int i) +{ + for (int k = 0; k < 9; k++) + { + if (arr[y][k] == i || arr[k][x] == i) + return false; + } + + for (int k = (y / 3) * 3; k < (y / 3) * 3 + 3; k++) + { + for (int j = (x / 3) * 3; j < (x / 3) * 3 + 3; j++) + { + if (arr[k][j] == i) + return false; + } + } + + return true; +} + +bool dfs(int n) +{ + if (n == Vec.size()) + return true; + + int y = Vec[n].first; + int x = Vec[n].second; + + for (int i = 1; i <= 9; i++) + { + if (check(y, x, i)) + { + arr[y][x] = i; + + if (dfs(n + 1)) + return true; + + arr[y][x] = 0; + } + } + + return false; +} + +int main() +{ + // 입력 속도 업 + ios::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + for (auto & i : arr) for (int & j : i) cin >> j; + + for (int i = 0; i < 9; i++) + { + for (int j = 0; j < 9; j++) + { + if (arr[i][j] == 0) + Vec.push_back({i, j}); + } + } + + dfs(0); + + cout << endl; + + for (auto & i : arr) + { + for (int & j : i) cout << j << ' '; + cout << endl; + } + + return 0; +} \ No newline at end of file From 368c16c6582a843b73a74ca6dcf1801c1ab63d80 Mon Sep 17 00:00:00 2001 From: LimSW Date: Mon, 20 Sep 2021 03:45:43 +0900 Subject: [PATCH 3/3] LimSangW boj15684 --- WEEK2-A/swlim/boj15684.cpp | 123 +++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 WEEK2-A/swlim/boj15684.cpp diff --git a/WEEK2-A/swlim/boj15684.cpp b/WEEK2-A/swlim/boj15684.cpp new file mode 100644 index 00000000..f3e9274f --- /dev/null +++ b/WEEK2-A/swlim/boj15684.cpp @@ -0,0 +1,123 @@ +#include + +int N, M, H; + +int MAP[30 + 5][10 + 5]; + +void input() +{ + scanf("%d %d %d", &N, &M, &H); + + for (int r = 0; r <= H + 1; r++) + for (int c = 0; c <= N + 1; c++) + MAP[r][c] = 3; /* 벽 설치 */ + + for (int r = 1; r <= H; r++) + for (int c = 1; c <= N; c++) + MAP[r][c] = 0; + + for (int i = 0; i < M; i++) + { + int r, c; + + scanf("%d %d", &r, &c); + + MAP[r][c] = 1; + MAP[r][c + 1] = 2; + } + + return; +} + +void output() +{ + for (int r = 0; r <= H + 1; r++) + { + for (int c = 0; c <= N + 1; c++) + printf("%d ", MAP[r][c]); + putchar('\n'); + } +} + +int check() +{ + for (int ladder = 1; ladder <= N; ladder++) + { + int sr, sc; + + sr = 1; + sc = ladder; + + while (1) + { + if (sr == H + 1) break; + + if (MAP[sr][sc] == 0) sr++; + else + { + if (MAP[sr][sc] == 1) sc++, sr++; + else sc--, sr++; + } + } + + if (ladder != sc) return 0; + } + + return 1; +} + +int PASS = 0; +void DFS(int L, int sr, int max) +{ + if (L == max) + { + // output(); + if (check()) PASS = 1; + return; + } + + for (int r = sr; r <= H; r++) + { + for (int c = 1; c <= N; c++) + { + if (MAP[r][c] == 1 || MAP[r][c] == 2 + || MAP[r][c + 1] == 1 || MAP[r][c + 1] == 3) continue; + + MAP[r][c] = 1; + MAP[r][c + 1] = 2; + + DFS(L + 1, r, max); + + MAP[r][c] = 0; + MAP[r][c + 1] = 0; + } + } +} + +int main(void) +{ + int sr, sc; + + input(); + + if (check()) /* 사다리 설치가 필요 없는 경우 */ + { + printf("0\n"); + return 0; + } + + for (int setup = 1; setup <= 3; setup++) + { + DFS(0, 1, setup); + + if (PASS) + { + printf("%d\n", setup); + return 0; + } + } + + printf("-1\n"); + + return 0; +} \ No newline at end of file