From 0591b50e49610cf008e1d7bcaa5693802cfe5cb2 Mon Sep 17 00:00:00 2001 From: yuyu0830 Date: Fri, 12 Apr 2024 23:30:38 +0900 Subject: [PATCH 1/2] =?UTF-8?q?24/04/12=20=EC=95=8C=EA=B3=A0=EB=A6=AC?= =?UTF-8?q?=EC=A6=98=20=EC=88=98=EC=97=85=20-=20=EB=B2=84=EB=B8=94=20?= =?UTF-8?q?=EC=A0=95=EB=A0=AC=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "yuyu0830/\354\240\225\353\240\254/23970.cpp" | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 "yuyu0830/\354\240\225\353\240\254/23970.cpp" diff --git "a/yuyu0830/\354\240\225\353\240\254/23970.cpp" "b/yuyu0830/\354\240\225\353\240\254/23970.cpp" new file mode 100644 index 0000000..c7120c1 --- /dev/null +++ "b/yuyu0830/\354\240\225\353\240\254/23970.cpp" @@ -0,0 +1,58 @@ +#include + +#define fastio cin.tie(NULL); cin.sync_with_stdio(false); + +using namespace std; + +int arr[2][10001] = {0, }; +int n, arrPtr = 0; + +bool same() { + // start at 'arrPtr' + for (int i = arrPtr; i < n; i++) { + // if diff, terminate this function + if (arr[0][i] != arr[1][i]) return false; + // if same, then that index will same forever. no reason to compare again. + arrPtr++; + } + return true; +} + +int main() { + fastio + cin >> n; + for (int i = 0; i < 2; i++) + for (int j = 0; j < n; j++) + cin >> arr[i][j]; + + int rnd = n - 1, ptr = 0; + + // it can be same before sort + if (same()) { + printf("1\n"); + return 0; + } + + while (rnd) { + // sort [0] to [ptr - rnd] + int a = arr[0][ptr]; + int b = arr[0][ptr + 1]; + + arr[0][ptr] = min(a, b); + arr[0][ptr + 1] = max(a, b); + + // if this index is last index in this round + if (++ptr == rnd) { + // next round + ptr = 0; + rnd--; + } + + if (same()) { + // if arr is same + printf("1\n"); + return 0; + } + } + printf("0\n"); +} \ No newline at end of file From f9900387cee187992b7ef3fae5cf0d32398ea2fc Mon Sep 17 00:00:00 2001 From: yuyu0830 Date: Mon, 29 Apr 2024 23:13:41 +0900 Subject: [PATCH 2/2] =?UTF-8?q?24-04-29=20=EB=B9=84=EC=88=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yuyu0830/README.md | 1 + "yuyu0830/\355\203\220\354\203\211/1799.cpp" | 68 ++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 "yuyu0830/\355\203\220\354\203\211/1799.cpp" diff --git a/yuyu0830/README.md b/yuyu0830/README.md index 3789a65..c0eb553 100644 --- a/yuyu0830/README.md +++ b/yuyu0830/README.md @@ -8,4 +8,5 @@ | 4차시 | 2024.03.26 | 분할정복 | [행렬 제곱](https://www.acmicpc.net/problem/10830) | - | | 5차시 | 2024.03.29 | 탐색 | [스도쿠](https://www.acmicpc.net/problem/2239) | - | | 6차시 | 2024.04.03 | 자료구조 | [나만 안되는 연애](https://www.acmicpc.net/problem/14621) | - | +| 10차시| 2024.04.29 | 백트래킹 | [비숍](https://www.acmicpc.net/problem/1799) | - | --- diff --git "a/yuyu0830/\355\203\220\354\203\211/1799.cpp" "b/yuyu0830/\355\203\220\354\203\211/1799.cpp" new file mode 100644 index 0000000..2e45b5f --- /dev/null +++ "b/yuyu0830/\355\203\220\354\203\211/1799.cpp" @@ -0,0 +1,68 @@ +#include +#include + +using namespace std; + +typedef pair ii; + +int leftArr[2][11] = {0, }; +int rightArr[2][11] = {0, }; +int map[11][11] = {0, }; + +int n, ans[2] = {0, }, m[2] = {0, }; +vector v[2]; + +void solve(int color, int idx) { + // current color, idx bishop's position + int x = v[color][idx].first; + int y = v[color][idx].second; + + // position about each diagonal direction + int rightPos = (x + y) / 2; + int leftPos = ((n - x - 1) + y) / 2; + + // if can set bishop in (x, y) position + if (map[x][y] && !rightArr[color][rightPos] && !leftArr[color][leftPos]) { + // then check diagonal position + rightArr[color][rightPos] = 1; + leftArr[color][leftPos] = 1; + + // update max value + m[color] = max(m[color], ++ans[color]); + + // search same color, another position bishop + for (int i = idx + 1; i < v[color].size(); i++) + solve(color, i); + + // set off current bishop + rightArr[color][rightPos] = 0; + leftArr[color][leftPos] = 0; + + ans[color]--; + } +} + +int main() { + cin >> n; + + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + int t; cin >> t; + map[i][j] = t; + // if bishop can set in (i, j) push in vector[board color] + if (t) v[i % 2 != j % 2].push_back(make_pair(i, j)); + } + } + + for (int color = 0; color < 2; color++) { + for (int i = 0; i < v[color].size(); i++) { + // search every position that can set in bishop + solve(color, i); + + // if (left bishop + current max value) less then max value then break this search + if (ans[color] + (v[color].size() - i - 1) < m[color]) break; + } + } + + printf("%d\n", m[0] + m[1]); +} \ No newline at end of file