From bc5540986dd7d58d555737b3e704b570c30a5c08 Mon Sep 17 00:00:00 2001 From: Macesuted Date: Fri, 6 Sep 2024 08:14:18 +0800 Subject: [PATCH] QOJ: The 3rd Universal Cup. Stage 5: Moscow --- QOJ/9135.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ QOJ/9136.cpp | 37 ++++++++++++++++++++++++++ QOJ/9142.cpp | 38 +++++++++++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 QOJ/9135.cpp create mode 100644 QOJ/9136.cpp create mode 100644 QOJ/9142.cpp diff --git a/QOJ/9135.cpp b/QOJ/9135.cpp new file mode 100644 index 0000000..7726e4d --- /dev/null +++ b/QOJ/9135.cpp @@ -0,0 +1,74 @@ +/** + * @file 9135.cpp + * @author Macesuted (i@macesuted.moe) + * @date 2024-09-03 + * + * @copyright Copyright (c) 2024 + * + */ + +#include +using namespace std; + +#define endl '\n' + +#define maxn 505 + +typedef pair pii; +typedef pair pli; + +int64_t a[maxn], f[maxn][maxn]; +vector graph[maxn]; +bool vis[maxn]; + +void solve(void) { + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + + for (int len = 2; len <= n; len++) { + priority_queue, greater> que; + for (int i = 1; i <= n; i++) graph[i].clear(), vis[i] = false; + + for (int l = 1, r = len; r <= n; l++, r++) { + f[l][r] = 1e18; + for (int c = 1; c <= n; c++) { + int clen = min(c - 1, n - c), cl = c - clen, cr = c + clen; + + auto rev = [&](int p) { return p + (c - p) * 2; }; + + int pl = rev(r), pr = rev(l); + if (1 <= pl && pr <= n) graph[pl].emplace_back(l, a[c]); + + if (cl == 1) { + if (cr >= r || cr < l) continue; + f[l][r] = min(f[l][r], max(f[rev(cr)][rev(l)], f[cr + 1][r]) + a[c]); + } else { + if (cl <= l || cl > r) continue; + f[l][r] = min(f[l][r], max(f[rev(r)][rev(cl)], f[l][cl - 1]) + a[c]); + } + } + que.emplace(f[l][r], l); + } + while (!que.empty()) { + int p = que.top().second; + que.pop(); + if (vis[p]) continue; + vis[p] = true; + for (auto [i, d] : graph[p]) + if (f[i][i + len - 1] > f[p][p + len - 1] + d) que.emplace(f[i][i + len - 1] = f[p][p + len - 1] + d, i); + } + } + + cout << f[1][n] << endl; + return; +} + +int main() { + ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); + + int _ = 1; + while (_--) solve(); + + return 0; +} diff --git a/QOJ/9136.cpp b/QOJ/9136.cpp new file mode 100644 index 0000000..11cab89 --- /dev/null +++ b/QOJ/9136.cpp @@ -0,0 +1,37 @@ +/** + * @file 9136.cpp + * @author Macesuted (i@macesuted.moe) + * @date 2024-09-03 + * + * @copyright Copyright (c) 2024 + * + */ + +#include +using namespace std; + +#define endl '\n' +void solve(void) { + int n = 4, k = 2048; + cout << 25 << endl; + cout << "$0 = $1 * " << fixed << 1. / k << endl; + for (int i = 1; i <= n; i++) cout << "$" << i << " = $0 * $" << i - 1 << endl; + for (int i = 1; i <= n; i++) { + double frac = 1; + for (int j = 1; j <= i + 1; j++) frac /= j; + cout << "$" << i << " = $" << i << " * " << fixed << frac << endl; + } + cout << "$0 = $0 + 1" << endl; + for (int i = 1; i <= n; i++) cout << "$0 = $0 + $" << i << endl; + for (int i = 2; i <= k; i *= 2) cout << "$0 = $0 * $0" << endl; + return; +} + +int main() { + ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); + + cout << setprecision(15); + solve(); + + return 0; +} diff --git a/QOJ/9142.cpp b/QOJ/9142.cpp new file mode 100644 index 0000000..6325937 --- /dev/null +++ b/QOJ/9142.cpp @@ -0,0 +1,38 @@ +/** + * @file 9142.cpp + * @author Macesuted (i@macesuted.moe) + * @date 2024-09-03 + * + * @copyright Copyright (c) 2024 + * + */ + +#include +using namespace std; + +#define endl '\n' + +#define maxn 200005 + +int a[maxn]; + +void solve(void) { + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + int64_t sum = 0; + sort(a + 1, a + n + 1); + for (int i = 1; i < n; i++) sum += a[i]; + cout << sum << endl; + return; +} + +int main() { + ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); + + int _ = 1; + cin >> _; + while (_--) solve(); + + return 0; +} \ No newline at end of file