0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 18:48:48 +00:00

Compare commits

...

10 Commits

Author SHA1 Message Date
5960485241
Add bjtu 2022-09-13 10:31:36 +08:00
7142277b40
1996 - 铁憨憨骑士团的课后作业
77493
2022-09-13 09:01:51 +08:00
e4e338fdbf
1987 - 小丑竟在我身边
77475
2022-09-12 21:37:01 +08:00
bce5bef444
1986 - 构造集合
77474
2022-09-12 21:36:22 +08:00
f7a8f3f7c5
1991 - 铁憨憨骑士团的课后习题
77473
2022-09-12 21:35:53 +08:00
d69dbf968c
1990 - 排队
77472
2022-09-12 21:35:45 +08:00
db3c853893
1995 - 暗影岛的歌声
77471
2022-09-12 21:35:38 +08:00
d4e5d47133
1981 - 铁憨憨骑士团的缎带分配
77470
2022-09-12 21:35:18 +08:00
6746568778
P3592 [POI2015] MYJ
https://www.luogu.com.cn/record/86488210
2022-09-12 19:39:53 +08:00
fff2f5cd1d
P3607 [USACO17JAN]Subsequence Reversal P
https://www.luogu.com.cn/record/86419056
2022-09-12 08:51:28 +08:00
10 changed files with 504 additions and 0 deletions

111
Luogu/P3592/P3592.cpp Normal file
View File

@ -0,0 +1,111 @@
#include <iostream>
#include <algorithm>
#include <numeric>
#include <tuple>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
std::vector<std::tuple<int, int, int>> data(m);
std::vector<int> nums;
for (auto& e : data) {
int a, b, c;
cin >> a >> b >> c;
e = std::make_tuple(a - 1, b - 1, c);
nums.push_back(c);
}
std::sort(nums.begin(), nums.end());
nums.erase(std::unique(nums.begin(), nums.end()), nums.end());
for (auto& e : data) {
std::get<2>(e) = std::lower_bound(nums.begin(), nums.end(), std::get<2>(e)) - nums.begin();
}
std::vector<std::vector<int>> g(n, std::vector<int>(nums.size(), 0));
std::vector<std::vector<std::vector<int>>>
f(n, std::vector<std::vector<int>>(n, std::vector<int>(nums.size(), 0))),
pos(n, std::vector<std::vector<int>>(n, std::vector<int>(nums.size(), 0))),
pre(n, std::vector<std::vector<int>>(n, std::vector<int>(nums.size(), 0)));
for (int len = 1; len <= n; len++) {
for (int l = 0, r = l + len - 1; r < n; l++, r++) {
std::for_each(g.begin() + l, g.begin() + r + 1, [&](auto& v) {
std::fill(v.begin(), v.end(), 0);
});
for (const auto& e : data) {
int a, b, c;
std::tie(a, b, c) = e;
if (l <= a && b <= r) {
std::for_each(g.begin() + a, g.begin() + b + 1, [&](auto& v) { v[c]++; });
}
}
std::for_each(g.begin() + l, g.begin() + r + 1, [&](auto& v) {
std::partial_sum(v.rbegin(), v.rend(), v.rbegin());
});
for (int i = nums.size() - 1; i >= 0; i--) {
int max = 0;
for (int j = l; j <= r; j++) {
int t = (j > 0 ? f[l][j - 1][i] : 0)
+ (j + 1 < n ? f[j + 1][r][i] : 0)
+ g[j][i] * nums[i];
if (max <= t) {
max = t;
pos[l][r][i] = j;
}
}
if (i + 1 == nums.size() || f[l][r][i + 1] <= max) {
f[l][r][i] = max;
pre[l][r][i] = i;
} else {
f[l][r][i] = f[l][r][i + 1];
pre[l][r][i] = pre[l][r][i + 1];
}
}
}
}
cout << f[0][n - 1][0] << endl;
std::vector<int> ans(n);
auto dfs = [&](int l, int r, int k, auto&& dfs) -> void {
if (l > r) return;
int p = pos[l][r][k = pre[l][r][k]];
ans[p] = nums[k];
dfs(l, p - 1, k, dfs);
dfs(p + 1, r, k, dfs);
};
dfs(0, n - 1, 0, dfs);
for (const int& x : ans) {
cout << x << ' ';
}
cout << endl;
return 0;
}

57
Luogu/P3607/P3607.cpp Normal file
View File

@ -0,0 +1,57 @@
#include <iostream>
#include <algorithm>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 55;
int n, a[N], f[N][N][N][N];
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int l = 1; l <= n; l++) {
for (int i = 1; i <= a[l]; i++) {
for (int j = a[l]; j <= 50; j++) {
f[l][l][i][j] = 1;
}
}
}
for (int len = 2; len <= n; len++) {
for (int l = 1, r = len; r <= n; l++, r++) {
for (int i = 1; i <= 50; i++) {
for (int j = i; j <= 50; j++) {
f[l][r][i][j] = std::max({
f[l][r][i][j],
f[l + 1][r][i][j] + (a[l] == i),
f[l][r - 1][i][j] + (a[r] == j),
f[l + 1][r - 1][i][j] + (a[r] == i) + (a[l] == j),
});
f[l][r][i][j + 1] = std::max(f[l][r][i][j + 1], f[l][r][i][j]);
f[l][r][i - 1][j] = std::max(f[l][r][i - 1][j], f[l][r][i][j]);
}
}
for (int j = 1; j <= 50; j++) {
for (int i = j; i; i--) {
f[l][r][i - 1][j] = std::max(f[l][r][i - 1][j], f[l][r][i][j]);
}
}
}
}
cout << f[1][n][1][50] << endl;
return 0;
}

View File

@ -81,6 +81,7 @@ git submodule update --init --recursive
| ------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------ | ----------------------------------- | | ------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------ | ----------------------------------- |
| [`AcWing`](./AcWing/) | [![AcWing](https://arina.loli.net/2022/05/29/P2bn7gmuZKvAqIV.png/250/50)](https://www.acwing.com/problem/) | [宝硕](https://www.acwing.com/user/myspace/index/32848/) | 部分题目为权限题,需购买对应课程。 | | [`AcWing`](./AcWing/) | [![AcWing](https://arina.loli.net/2022/05/29/P2bn7gmuZKvAqIV.png/250/50)](https://www.acwing.com/problem/) | [宝硕](https://www.acwing.com/user/myspace/index/32848/) | 部分题目为权限题,需购买对应课程。 |
| [`AtCoder`](./AtCoder/) | [![AtCoder](https://arina.loli.net/2022/05/29/wZ2Ge4uRt7S9Qxz.png/1000/75)](https://atcoder.jp/contests/archive) | [baoshuo](https://atcoder.jp/users/baoshuo) | 题目为比赛题。 | | [`AtCoder`](./AtCoder/) | [![AtCoder](https://arina.loli.net/2022/05/29/wZ2Ge4uRt7S9Qxz.png/1000/75)](https://atcoder.jp/contests/archive) | [baoshuo](https://atcoder.jp/users/baoshuo) | 题目为比赛题。 |
| [`bjtu`](./bjtu/) | [acm.bjtu](https://citel.bjtu.edu.cn/acm/problem) | [宝硕](https://citel.bjtu.edu.cn/acm/user/4252) | |
| [`BZOJ`](./BZOJ/) | [Hydro BZOJ 域](https://hydro.ac/d/bzoj/)、[DarkBZOJ](https://darkbzoj.tk/problems) | - | 原 BZOJ 已经停止运营。 | | [`BZOJ`](./BZOJ/) | [Hydro BZOJ 域](https://hydro.ac/d/bzoj/)、[DarkBZOJ](https://darkbzoj.tk/problems) | - | 原 BZOJ 已经停止运营。 |
| [`Codeforces`](./Codeforces/) | [![Codeforces](https://arina.loli.net/2022/05/29/34Lz8cShuaVDEZI.png/250/50)](https://codeforces.com/problemset) | [baoshuo](https://codeforces.com/profile/baoshuo) | | | [`Codeforces`](./Codeforces/) | [![Codeforces](https://arina.loli.net/2022/05/29/34Lz8cShuaVDEZI.png/250/50)](https://codeforces.com/problemset) | [baoshuo](https://codeforces.com/profile/baoshuo) | |
| [`Gym`](./Gym/) | [![Codeforces::Gym](https://arina.loli.net/2022/05/29/34Lz8cShuaVDEZI.png/250/50)](https://codeforces.com/gyms) | [baoshuo](https://codeforces.com/profile/baoshuo) | | | [`Gym`](./Gym/) | [![Codeforces::Gym](https://arina.loli.net/2022/05/29/34Lz8cShuaVDEZI.png/250/50)](https://codeforces.com/gyms) | [baoshuo](https://codeforces.com/profile/baoshuo) | |

30
bjtu/1981/1981.cpp Normal file
View File

@ -0,0 +1,30 @@
#include <iostream>
#include <algorithm>
#include <utility>
using std::cin;
using std::cout;
const char endl = '\n';
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
while (n--) {
std::pair<int, int> p[2];
for (int i = 0; i < 2; i++) {
cin >> p[i].first >> p[i].second;
}
std::sort(p, p + 2);
cout << (p[1].first < p[0].second ? "YES" : "NO") << endl;
}
return 0;
}

60
bjtu/1986/1986.cpp Normal file
View File

@ -0,0 +1,60 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e5 + 5;
const int primes[] = {0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 47, 51, 53};
const int ci[] = {0, 6, 3, 2, 1, 1, 1, 1, 1, 1, 1};
int n, cnt;
long long a[N];
long long k = 9316358251200;
long long binpow(long long a, long long b) {
long long res = 1;
while (b) {
if (b & 1) res *= a;
a *= a;
b >>= 1;
}
return res;
}
void dfs(int step, long long now) {
if (step == 10) {
a[++cnt] = now;
return;
}
for (int i = 0; i <= ci[step + 1]; i++) {
dfs(step + 1, now * binpow(primes[step + 1], i));
}
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
dfs(0, 1);
for (int i = 1; i <= n; i++) {
cout << k * i + 1 << ' ';
}
cout << endl;
for (int i = 2; i <= n + 1; i++) {
cout << a[i] << ' ';
}
cout << endl;
return 0;
}

48
bjtu/1987/1987.cpp Normal file
View File

@ -0,0 +1,48 @@
#include <iostream>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e4 + 5;
int n, m, cnt, cnt2;
std::vector<int> g[N];
bool vis[N], flag = true;
void dfs(int u) {
cnt++;
vis[u] = true;
for (int v : g[u]) {
if (!vis[v]) dfs(v);
}
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 1, u, v; i <= m; i++) {
cin >> u >> v;
g[u].emplace_back(v);
g[v].emplace_back(u);
}
for (int i = 1; i <= n; i++) {
if (!vis[i]) {
int pre = cnt;
dfs(i);
if (cnt - pre > 1) cnt2++;
}
}
cout << (cnt2 <= 1 ? "YES" : "NO") << endl;
return 0;
}

38
bjtu/1990/1990.cpp Normal file
View File

@ -0,0 +1,38 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 2e5 + 5;
int n, a[N], b[N], s1[N], s2[N], ans;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
cin >> b[i];
}
for (int i = 1; i <= n; i++) {
s1[i] = s1[i - 1] + (a[i] == b[i]);
s2[i] = s2[i - 1] + (a[i] == b[i - 1]);
}
ans = s2[n];
for (int i = 1; i <= n; i++) {
ans = std::max(ans, s1[i - 1] + s2[n] - s2[i] + (a[i] == b[n]));
}
cout << ans << endl;
return 0;
}

64
bjtu/1991/1991.cpp Normal file
View File

@ -0,0 +1,64 @@
#include <iostream>
#include <numeric>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
bool is_prime(int x) {
if (x <= 1) return false;
for (int i = 2; i * i <= x; i++) {
if (x % i == 0) {
return false;
}
}
return true;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, t;
std::vector<int> p;
cin >> n;
if (is_prime(n)) {
cout << "NO" << endl;
exit(0);
}
t = n;
for (int i = 2; i * i <= t; i++) {
while (t % i == 0) {
p.emplace_back(i);
t /= i;
}
}
if (t > 1) p.emplace_back(t);
int sum = std::accumulate(p.begin(), p.end(), 0);
cout << "YES" << endl
<< static_cast<int>(p.size()) + (n - sum) << endl;
for (const int& x : p) {
cout << x << ' ';
}
while (sum < n) {
cout << 1 << ' ';
sum++;
}
cout << endl;
return 0;
}

31
bjtu/1995/1995.cpp Normal file
View File

@ -0,0 +1,31 @@
#include <iostream>
#include <iomanip>
#include <string>
using std::cin;
using std::cout;
const char endl = '\n';
const double d[] = {0, 261.6, 293.6, 329.6, 349.2, 392.0, 440.0, 493.8};
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
std::string s;
double ans = 0;
cin >> s;
for (int i = 1; i < s.size(); i++) {
if (s[i] == '-') s[i] = s[i - 1];
}
for (char c : s) {
ans += d[c - '0'];
}
cout << std::fixed << std::setprecision(6) << ans / s.size() << endl;
return 0;
}

64
bjtu/1996/1996.cpp Normal file
View File

@ -0,0 +1,64 @@
#include <iostream>
#include <numeric>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
bool is_prime(int x) {
if (x <= 1) return false;
for (int i = 2; i * i <= x; i++) {
if (x % i == 0) {
return false;
}
}
return true;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, t;
std::vector<int> p;
cin >> n;
if (is_prime(n)) {
cout << "NO" << endl;
exit(0);
}
t = n;
for (int i = 2; i * i <= t; i++) {
while (t % i == 0) {
p.emplace_back(i);
t /= i;
}
}
if (t > 1) p.emplace_back(t);
int sum = std::accumulate(p.begin(), p.end(), 0);
cout << "YES" << endl
<< static_cast<int>(p.size()) + (n - sum) << endl;
for (const int& x : p) {
cout << x << ' ';
}
while (sum < n) {
cout << 1 << ' ';
sum++;
}
cout << endl;
return 0;
}