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

Compare commits

..

5 Commits

155 changed files with 763 additions and 0 deletions

78
LibreOJ/2071/2071.cpp Normal file
View File

@ -0,0 +1,78 @@
#include <iostream>
#include <algorithm>
#include <array>
#include <iomanip>
#include <limits>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 2505;
const double eps = 1e-4;
int k, n;
std::array<int, N> siz;
std::array<double, N> d;
std::array<std::array<double, N>, N> f;
std::array<std::vector<int>, N> g;
std::array<std::pair<int, int>, N> a;
void dfs(int u) {
f[u][1] = d[u];
siz[u] = 1;
for (int v : g[u]) {
dfs(v);
siz[u] += siz[v];
for (int i = std::min(siz[u], k + 1); i; i--) {
for (int j = 0; j <= std::min(siz[v], i - 1); j++) {
f[u][i] = std::max(f[u][i], f[u][i - j] + f[v][j]);
}
}
}
}
bool check(double mid) {
for (int i = 1; i <= n; i++) {
d[i] = static_cast<double>(a[i].second) - mid * a[i].first;
}
std::for_each(f.begin(), f.end(), [&](auto &x) {
std::fill(x.begin(), x.end(), std::numeric_limits<int>::min());
});
dfs(0);
return f[0][k + 1] >= 0;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> k >> n;
for (int i = 1, r; i <= n; i++) {
cin >> a[i].first >> a[i].second >> r;
g[r].emplace_back(i);
}
double l = 0,
r = 10000;
while (r - l > eps) {
double mid = (l + r) / 2;
if (check(mid)) l = mid;
else r = mid;
}
cout << std::fixed << std::setprecision(3) << l << endl;
return 0;
}

BIN
LibreOJ/2071/data/team0.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2071/data/team0.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2071/data/team1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2071/data/team1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2071/data/team2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2071/data/team2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2071/data/team3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2071/data/team3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2071/data/team4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2071/data/team4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2071/data/team5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2071/data/team5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2071/data/team6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2071/data/team6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2071/data/team7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2071/data/team7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2071/data/team8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2071/data/team8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2071/data/team9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2071/data/team9.out (Stored with Git LFS) Normal file

Binary file not shown.

64
LibreOJ/2431/2431.cpp Normal file
View File

@ -0,0 +1,64 @@
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 5005;
int n, max_dep;
long long ans;
std::vector<int> g[N];
std::array<int, N> f1, f2, cnt;
void dfs(int u, int f, int d) {
cnt[d]++;
max_dep = std::max(max_dep, d);
for (int v : g[u]) {
if (v == f) continue;
dfs(v, u, d + 1);
}
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1, u, v; i < n; i++) {
cin >> u >> v;
g[u].emplace_back(v);
g[v].emplace_back(u);
}
dfs(1, 0, 1);
for (int i = 1; i <= n; i++) {
std::fill(f1.begin(), f1.end(), 0);
std::fill(f2.begin(), f2.end(), 0);
for (int u : g[i]) {
max_dep = 0;
std::fill(cnt.begin(), cnt.end(), 0);
dfs(u, i, 1);
for (int j = 1; j <= max_dep; j++) {
ans += f1[j] * cnt[j];
f1[j] += f2[j] * cnt[j];
f2[j] += cnt[j];
}
}
}
cout << ans << endl;
return 0;
}

BIN
LibreOJ/2431/data/hot0.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot0.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot10a.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot10a.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot10b.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot10b.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot1a.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot1a.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot1b.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot1b.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot1c.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot1c.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot1d.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot1d.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot1e.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot1e.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot2a.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot2a.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot2b.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot2b.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot3a.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot3a.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot3b.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot3b.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot4a.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot4a.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot4b.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot4b.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot5a.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot5a.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot5b.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot5b.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot6a.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot6a.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot6b.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot6b.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot7a.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot7a.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot7b.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot7b.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot8a.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot8a.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot8b.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot8b.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot9a.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot9a.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot9b.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2431/data/hot9b.out (Stored with Git LFS) Normal file

Binary file not shown.

64
Luogu/P3565/P3565.cpp Normal file
View File

@ -0,0 +1,64 @@
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 5005;
int n, max_dep;
long long ans;
std::vector<int> g[N];
std::array<int, N> f1, f2, cnt;
void dfs(int u, int f, int d) {
cnt[d]++;
max_dep = std::max(max_dep, d);
for (int v : g[u]) {
if (v == f) continue;
dfs(v, u, d + 1);
}
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1, u, v; i < n; i++) {
cin >> u >> v;
g[u].emplace_back(v);
g[v].emplace_back(u);
}
dfs(1, 0, 1);
for (int i = 1; i <= n; i++) {
std::fill(f1.begin(), f1.end(), 0);
std::fill(f2.begin(), f2.end(), 0);
for (int u : g[i]) {
max_dep = 0;
std::fill(cnt.begin(), cnt.end(), 0);
dfs(u, i, 1);
for (int j = 1; j <= max_dep; j++) {
ans += f1[j] * cnt[j];
f1[j] += f2[j] * cnt[j];
f2[j] += cnt[j];
}
}
}
cout << ans << endl;
return 0;
}

68
S2OJ/1538/1538.cpp Normal file
View File

@ -0,0 +1,68 @@
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 3005;
int n, root, max_dep;
long long ans;
std::vector<int> g[N];
std::array<int, N> f1, f2, cnt;
void dfs(int u, int f, int d) {
cnt[d]++;
max_dep = std::max(max_dep, d);
for (int v : g[u]) {
if (v == f) continue;
dfs(v, u, d + 1);
}
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1, x; i <= n; i++) {
cin >> x;
if (x) {
g[x].emplace_back(i);
g[i].emplace_back(x);
} else {
root = i;
}
}
dfs(root, 0, 1);
for (int i = 1; i <= n; i++) {
std::fill(f1.begin(), f1.end(), 0);
std::fill(f2.begin(), f2.end(), 0);
for (int u : g[i]) {
max_dep = 0;
std::fill(cnt.begin(), cnt.end(), 0);
dfs(u, i, 1);
for (int j = 1; j <= max_dep; j++) {
ans += f1[j] * cnt[j];
f1[j] += f2[j] * cnt[j];
f2[j] += cnt[j];
}
}
}
cout << ans << endl;
return 0;
}

BIN
S2OJ/1538/data/problem.conf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1538/data/tinytree1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1538/data/tinytree1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1538/data/tinytree10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1538/data/tinytree10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1538/data/tinytree11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1538/data/tinytree11.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1538/data/tinytree12.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1538/data/tinytree12.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1538/data/tinytree13.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1538/data/tinytree13.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1538/data/tinytree14.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1538/data/tinytree14.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1538/data/tinytree15.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1538/data/tinytree15.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1538/data/tinytree16.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1538/data/tinytree16.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1538/data/tinytree17.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1538/data/tinytree17.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1538/data/tinytree18.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1538/data/tinytree18.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1538/data/tinytree19.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1538/data/tinytree19.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1538/data/tinytree2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1538/data/tinytree2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1538/data/tinytree20.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1538/data/tinytree20.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1538/data/tinytree3.in (Stored with Git LFS) Normal file

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More