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

Compare commits

...

8 Commits

131 changed files with 835 additions and 0 deletions

56
BZOJ/3209/3209.cpp Normal file
View File

@ -0,0 +1,56 @@
#include <iostream>
#include <bitset>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 70;
const int mod = 1e7 + 7;
long long n, f[N][N][2], ans = 1;
long long binpow(long long a, long long b) {
a %= mod;
long long res = 1;
while (b) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
std::bitset<64> b(n);
n = 64 - __builtin_clzll(n) - 1 + 1;
b <<= 1;
f[0][0][1] = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
f[i + 1][j][0] += f[i][j][0];
f[i + 1][j + 1][0] += f[i][j][0];
f[i + 1][j][(b[i + 1] == 0)] += f[i][j][1];
if (b[i + 1] == 1) f[i + 1][j + 1][1] += f[i][j][1];
}
}
for (int i = 1; i <= 64; i++) {
ans = ans * binpow(i, f[n][i][0] + f[n][i][1]) % mod;
}
cout << ans << endl;
return 0;
}

BIN
BZOJ/3209/data/1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3209/data/1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3209/data/10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3209/data/10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3209/data/2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3209/data/2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3209/data/3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3209/data/3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3209/data/4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3209/data/4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3209/data/5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3209/data/5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3209/data/6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3209/data/6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3209/data/7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3209/data/7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3209/data/8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3209/data/8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3209/data/9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3209/data/9.out (Stored with Git LFS) Normal file

Binary file not shown.

59
LibreOJ/6097/6097.cpp Normal file
View File

@ -0,0 +1,59 @@
#include <iostream>
#include <algorithm>
#include <bitset>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 65;
const int mod = 1e7 + 7;
long long n, f[N][N][2], ans = 1;
std::bitset<65> b;
long long binpow(long long a, long long b) {
a %= mod;
long long res = 1;
while (b) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 0; i < 64; i++) {
b.set(64 - i, (n >> i) & 1);
}
f[0][0][1] = 1;
for (int i = 0; i < 64; i++) {
for (int j = 0; j <= i; j++) {
f[i + 1][j][0] += f[i][j][0];
f[i + 1][j + 1][0] += f[i][j][0];
f[i + 1][j][(b[i + 1] == 0)] += f[i][j][1];
if (b[i + 1] == 1)
f[i + 1][j + 1][1] += f[i][j][1];
}
}
for (int i = 1; i <= 64; i++) {
ans = ans * binpow(i, f[64][i][0] + f[64][i][1]) % mod;
}
cout << ans << endl;
return 0;
}

BIN
LibreOJ/6097/data/1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6097/data/1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6097/data/10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6097/data/10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6097/data/2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6097/data/2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6097/data/3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6097/data/3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6097/data/4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6097/data/4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6097/data/5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6097/data/5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6097/data/6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6097/data/6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6097/data/7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6097/data/7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6097/data/8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6097/data/8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6097/data/9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6097/data/9.out (Stored with Git LFS) Normal file

Binary file not shown.

81
Luogu/P2986/P2986.cpp Normal file
View File

@ -0,0 +1,81 @@
#include <iostream>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e5 + 5;
int n, sum, root, c[N], siz[N], max_siz[N], dep[N];
long long ans;
std::vector<std::pair<int, int>> g[N];
void dfs1(int u, int f) {
siz[u] = c[u];
for (auto e : g[u]) {
int v = e.first,
w = e.second;
if (v == f) continue;
dfs1(v, u);
siz[u] += siz[v];
max_siz[u] = std::max(max_siz[u], siz[v]);
}
max_siz[u] = std::max(max_siz[u], sum - siz[u]);
}
void dfs2(int u, int f) {
for (auto e : g[u]) {
int v = e.first,
w = e.second;
if (v == f) continue;
dep[v] = dep[u] + w;
dfs2(v, u);
}
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> c[i];
sum += c[i];
}
for (int i = 1, u, v, w; i <= n; i++) {
cin >> u >> v >> w;
g[u].emplace_back(v, w);
g[v].emplace_back(u, w);
}
dfs1(1, 0);
for (int i = 1; i <= n; i++) {
if (!root || max_siz[i] < max_siz[root]) {
root = i;
}
}
dep[0] = -1;
dfs2(root, 0);
for (int i = 1; i <= n; i++) {
ans += static_cast<long long>(c[i]) * dep[i];
}
cout << ans << endl;
return 0;
}

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

@ -0,0 +1,57 @@
#include <iostream>
#include <algorithm>
#include <bitset>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 65;
const int mod = 1e7 + 7;
long long n, f[N][N][2], ans = 1;
std::bitset<65> b;
long long binpow(long long a, long long b) {
a %= mod;
long long res = 1;
while (b) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 0; i < 64; i++) {
b.set(64 - i, (n >> i) & 1);
}
f[0][0][1] = 1;
for (int i = 0; i < 64; i++) {
for (int j = 0; j <= i; j++) {
f[i + 1][j][0] += f[i][j][0];
f[i + 1][j + 1][0] += f[i][j][0];
f[i + 1][j][(b[i + 1] == 0)] += f[i][j][1];
if (b[i + 1] == 1) f[i + 1][j + 1][1] += f[i][j][1];
}
}
for (int i = 1; i <= 64; i++) {
ans = ans * binpow(i, f[64][i][0] + f[64][i][1]) % mod;
}
cout << ans << endl;
return 0;
}

56
Luogu/P4377/P4377.cpp Normal file
View File

@ -0,0 +1,56 @@
#include <iostream>
#include <algorithm>
#include <cmath>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 255,
W = 1005;
const double eps = 1e-6;
int n, w, a[N], b[N];
double f[W];
bool check(double x) {
std::fill_n(f + 1, w, -1e9);
for (int i = 1; i <= n; i++) {
for (int j = w; j >= 0; j--) {
int k = std::min(w, j + a[i]);
f[k] = std::max(f[k], f[j] + b[i] - x * a[i]);
}
}
return f[w] >= 0;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> w;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
double l = 0,
r = 1e6;
while (r - l > eps) {
double mid = (l + r) / 2;
if (check(mid)) {
l = mid;
} else {
r = mid;
}
}
cout << static_cast<int>(std::floor(l * 1000)) << endl;
return 0;
}

BIN
Luogu/P4377/data/P4377_1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4377/data/P4377_1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4377/data/P4377_10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4377/data/P4377_10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4377/data/P4377_2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4377/data/P4377_2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4377/data/P4377_3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4377/data/P4377_3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4377/data/P4377_4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4377/data/P4377_4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4377/data/P4377_5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4377/data/P4377_5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4377/data/P4377_6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4377/data/P4377_6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4377/data/P4377_7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4377/data/P4377_7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4377/data/P4377_8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4377/data/P4377_8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4377/data/P4377_9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4377/data/P4377_9.out (Stored with Git LFS) Normal file

Binary file not shown.

40
S2OJ/1535/1535.cpp Normal file
View File

@ -0,0 +1,40 @@
#include <iostream>
#include <deque>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 2e6 + 5;
int n, a[N], b[N], ans;
std::deque<int> q;
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++) {
while (!q.empty() && b[i] >= b[q.front()]) q.pop_front();
q.push_front(i);
}
for (int i = 1; i <= n; i++) {
while (!q.empty() && q.back() <= i) q.pop_back();
if (!q.empty()) ans = std::max(ans, b[q.back()] - a[i]);
}
cout << ans << endl;
return 0;
}

BIN
S2OJ/1535/data/goods1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1535/data/goods1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1535/data/goods10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1535/data/goods10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1535/data/goods2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1535/data/goods2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1535/data/goods3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1535/data/goods3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1535/data/goods4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1535/data/goods4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1535/data/goods5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1535/data/goods5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1535/data/goods6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1535/data/goods6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1535/data/goods7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1535/data/goods7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1535/data/goods8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1535/data/goods8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1535/data/goods9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1535/data/goods9.out (Stored with Git LFS) Normal file

Binary file not shown.

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

Binary file not shown.

42
S2OJ/1536/1536.cpp Normal file
View File

@ -0,0 +1,42 @@
#include <iostream>
#include <string>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 20005;
int n, ans;
std::string s, t;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> s >> n;
int s_len = s.size();
for (int i = 1; i <= n; i++) {
cin >> t;
int t_len = t.size();
if (s_len == t_len) {
bool flag = true;
for (int i = 0; i < t_len; i++) {
if (s[i] != '#') {
flag &= s[i] == t[i];
}
}
if (flag) ans++;
}
}
cout << ans << endl;
return 0;
}

BIN
S2OJ/1536/data/matching1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1536/data/matching1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1536/data/matching10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1536/data/matching10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1536/data/matching2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1536/data/matching2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1536/data/matching3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1536/data/matching3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1536/data/matching4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1536/data/matching4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1536/data/matching5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1536/data/matching5.out (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