From b2505a5361b7e57295a89e1a2850f8dccf8f56fd Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 21 Oct 2024 21:41:32 +0800 Subject: [PATCH] =?UTF-8?q?:white=5Fcheck=5Fmark:=20P7912=20100pts=20?= =?UTF-8?q?=E9=98=9F=E5=88=97=20(used=20to=20be=20using=20vector,=20TLE)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 4 ++- bears-fruit-basket/data.in | 2 ++ bears-fruit-basket/main.cc | 68 ++++++++++++++++++++++++++++++++++++++ csp-backpack/data.in | 7 ++++ holiday-plan/main.cc | 9 +++++ insert-sort/main.cc | 52 ++++++++++++++--------------- sudoku/main.cc | 8 ++--- 7 files changed, 119 insertions(+), 31 deletions(-) create mode 100644 bears-fruit-basket/data.in create mode 100644 bears-fruit-basket/main.cc create mode 100644 csp-backpack/data.in create mode 100644 holiday-plan/main.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 8585a85..f608864 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,4 +28,6 @@ add_executable(Playground csp-decode/main.cc palin/main.cc csp-backpack/main.cc - csp-awarding/main.cc) + csp-awarding/main.cc + holiday-plan/main.cc + bears-fruit-basket/main.cc) diff --git a/bears-fruit-basket/data.in b/bears-fruit-basket/data.in new file mode 100644 index 0000000..ba3a862 --- /dev/null +++ b/bears-fruit-basket/data.in @@ -0,0 +1,2 @@ +12 +1 1 0 0 1 1 1 0 1 1 0 0 diff --git a/bears-fruit-basket/main.cc b/bears-fruit-basket/main.cc new file mode 100644 index 0000000..9213d4b --- /dev/null +++ b/bears-fruit-basket/main.cc @@ -0,0 +1,68 @@ +#include +#include +#include + +using namespace std; + +struct fruit { + int type; + int start; + int end; + + fruit(int t, int start, int end) { + this->type = t; + this->start = start; + this->end = end; + } +}; + +bool took[200000 + 5], fruits[200000 + 5]; + +int main() { + int n; + queue blocks, pending_blocks; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> fruits[i]; + } + fruits[n + 1] = !fruits[n]; // Make the last block can be handled + for (int ptr = 2, lead = 1; ptr <= n + 1; ptr++) { + if (fruits[ptr] != fruits[ptr - 1]) { + blocks.emplace(fruits[ptr - 1], lead, ptr - 1); + lead = ptr; + } + } + // 1st -> 1 1 0 0 1 1 1 0 1 1 0 0 + // x x x x x x + // 2nd -> 1 0 1 1 0 0 + int remain = n; + while (remain) { + while (!blocks.empty()) { + auto front = blocks.front(); + blocks.pop(); + while (took[front.start] && front.start <= front.end) front.start++; + if (front.start > front.end) continue; + printf("%d ", front.start); + remain--; + took[front.start] = true; + if (front.end == front.start) continue; + front.start++; + pending_blocks.push(front); + } + printf("\n"); + while (!pending_blocks.empty()) { + auto front = pending_blocks.front(); + pending_blocks.pop(); + while (!pending_blocks.empty()) { + auto back = pending_blocks.front(); + if (front.type == back.type) { + front.end = back.end; + pending_blocks.pop(); + } else { + break; + } + } + blocks.push(front); + } + } +} \ No newline at end of file diff --git a/csp-backpack/data.in b/csp-backpack/data.in new file mode 100644 index 0000000..2d49e36 --- /dev/null +++ b/csp-backpack/data.in @@ -0,0 +1,7 @@ +6 1 100 +50 +20 +25 +20 +25 +50 diff --git a/holiday-plan/main.cc b/holiday-plan/main.cc new file mode 100644 index 0000000..2eef5c7 --- /dev/null +++ b/holiday-plan/main.cc @@ -0,0 +1,9 @@ +#include + +using namespace std; + +int main() { + int n, m, k; + cin >> n >> m >> k; + +} \ No newline at end of file diff --git a/insert-sort/main.cc b/insert-sort/main.cc index f4ac7f1..f4ffb92 100644 --- a/insert-sort/main.cc +++ b/insert-sort/main.cc @@ -1,38 +1,38 @@ -// The question want me to impl a sort by my self -// But absolutely not - #include using namespace std; +const int N = 10005; + +pair arr[N]; +int b[N]; + int main() { - int n, Q; - cin >> n >> Q; - int arr[n + 5]; - + int n, m; + scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { - cin >> arr[i]; + scanf("%d", &arr[i].first); + arr[i].second = i; } - - for (int i = 0; i < Q; i++) { - int op; - cin >> op; + sort(arr + 1, arr + n + 1); + for (int i = 1; i <= n; i++) b[arr[i].second] = i; + while (m--) { + int op, x, y; + scanf("%d", &op); if (op == 1) { - int x, v; - cin >> x >> v; - arr[x] = v; + scanf("%d%d", &x, &y); + arr[b[x]].first = y; + for (int i = 1; i < n; i++) { + if (arr[i] > arr[i + 1]) swap(arr[i], arr[i + 1]); + } + for (int i = n - 1; i >= 1; i--) { + if (arr[i] > arr[i + 1]) swap(arr[i], arr[i + 1]); + } + for (int i = 1; i <= n; i++) b[arr[i].second] = i; } else { - int xn; - cin >> xn; - int it = arr[xn]; - int pos = n; - for (int j = 1; j < xn; j++) { - if (arr[j] > it) pos--; - } - for (int j = xn + 1; j <= n; j++) { - if (arr[j] >= it) pos--; - } - cout << pos << endl; + scanf("%d", &x); + printf("%d\n", b[x]); } } + return 0; } \ No newline at end of file diff --git a/sudoku/main.cc b/sudoku/main.cc index dedb9ef..fff0881 100644 --- a/sudoku/main.cc +++ b/sudoku/main.cc @@ -4,7 +4,7 @@ using namespace std; #define mx 100100 int sum = 0; -int a[10][10]; +int arr[10][10]; inline int read() { char c = getchar(); if (c == '.') @@ -84,7 +84,7 @@ struct dancing_link { v = (ansk[i]) % 9; if (v == 0) v = 9; - a[x][y] = v; + arr[x][y] = v; } return 1; } @@ -112,7 +112,7 @@ int main() { int o; for (int i = 0; i <= 8; i++) { for (int j = 0; j <= 8; j++) { - a[i][j] = x = read(); + arr[i][j] = x = read(); for (int k = 1; k <= 9; k++) { if (x != k && x != 0) continue; @@ -127,7 +127,7 @@ int main() { dlx.dance(0); for (int i = 0; i <= 8; i++) { for (int j = 0; j <= 8; j++) - printf("%d", a[i][j]); + printf("%d", arr[i][j]); printf("\n"); } return 0;