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

Compare commits

...

13 Commits

Author SHA1 Message Date
83d0904c97
P8470 [Aya Round 1 E] 乙(two)
https://www.luogu.com.cn/record/82833783
2022-08-07 17:25:23 +08:00
014ab1be4d
P8471 [Aya Round 1 F] 琪露诺的选择题
https://www.luogu.com.cn/record/82831979
2022-08-07 17:13:34 +08:00
4d36d6cd8e
P8469 [Aya Round 1 D] 文文的数学游戏
https://www.luogu.com.cn/record/82831636
2022-08-07 17:12:23 +08:00
790ac459f1
P8468 [Aya Round 1 C] 文文的构造游戏
https://www.luogu.com.cn/record/82831524
2022-08-07 17:11:22 +08:00
656d8b108f
P8467 [Aya Round 1 B] 幻想乡麻将游戏
https://www.luogu.com.cn/record/82831401
2022-08-07 17:10:41 +08:00
82f4ab0c86
P8466 [Aya Round 1 A] 幻想乡扑克游戏
https://www.luogu.com.cn/record/82831302
2022-08-07 17:09:57 +08:00
dc1c7f7f4c
T258621 [Aya Round 1 F] 琪露诺的选择题
https://www.luogu.com.cn/record/82821621
2022-08-07 16:24:06 +08:00
2e465457b6
T258418 [Aya Round 1 D] 文文的数学游戏
https://www.luogu.com.cn/record/82796877
2022-08-07 14:35:17 +08:00
dd86807035
T258480 [Aya Round 1 C] 文文的构造游戏
https://www.luogu.com.cn/record/82793996
2022-08-07 14:23:16 +08:00
06e8fe6606
T258573 [Aya Round 1 B] 幻想乡麻将游戏
https://www.luogu.com.cn/record/82791696
2022-08-07 14:13:44 +08:00
bba92de9e1
T258478 [Aya Round 1 A] 幻想乡扑克游戏
https://www.luogu.com.cn/record/82790224
2022-08-07 14:07:16 +08:00
7b46d073f1
950. 郁闷的出纳员
https://www.acwing.com/problem/content/submission/code_detail/16213761/
2022-08-07 10:17:55 +08:00
e9b2b1292b
2189. 有源汇上下界最大流
https://www.acwing.com/problem/content/submission/code_detail/16213605/
2022-08-07 10:13:21 +08:00
10 changed files with 568 additions and 0 deletions

128
AcWing/2189/2189.cpp Normal file
View File

@ -0,0 +1,128 @@
#include <iostream>
#include <cstring>
#include <limits>
#include <queue>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 205,
M = 10205;
int n, m, s, t, ss, tt;
int idx, head[N], ver[M << 2], edge[M << 2], next[M << 2];
int f[N], d[N], cur[N];
void add(int u, int v, int w) {
ver[idx] = v;
edge[idx] = w;
next[idx] = head[u];
head[u] = idx++;
}
bool bfs() {
memset(d, 0x00, sizeof(d));
std::queue<int> q;
q.push(s);
d[s] = 1;
cur[s] = head[s];
while (!q.empty()) {
int u = q.front();
q.pop();
for (int i = head[u]; ~i; i = next[i]) {
int v = ver[i],
w = edge[i];
if (!d[v] && w) {
d[v] = d[u] + 1;
cur[v] = head[v];
if (v == t) return true;
q.push(v);
}
}
}
return false;
}
int dinic(int u, int limit) {
if (u == t) return limit;
int flow = 0;
for (int &i = cur[u]; ~i && flow < limit; i = next[i]) {
int v = ver[i],
w = edge[i];
if (d[v] == d[u] + 1 && w) {
int k = dinic(v, std::min(w, limit - flow));
if (!k) d[v] = 0;
edge[i] -= k;
edge[i ^ 1] += k;
flow += k;
}
}
return flow;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
memset(head, 0xff, sizeof(head));
cin >> n >> m >> ss >> tt;
for (int i = 1, u, v, a, b; i <= m; i++) {
cin >> u >> v >> a >> b;
add(u, v, b - a);
add(v, u, 0);
f[u] -= a, f[v] += a;
}
int sum = 0;
s = 0, t = n + 1;
for (int i = 1; i <= n; i++) {
if (f[i] > 0) {
add(s, i, f[i]);
add(i, s, 0);
sum += f[i];
} else if (f[i] < 0) {
add(i, t, -f[i]);
add(t, i, 0);
}
}
add(tt, ss, std::numeric_limits<int>::max());
add(ss, tt, 0);
int res = 0, flow;
while (bfs()) {
while (flow = dinic(s, std::numeric_limits<int>::max())) res += flow;
}
if (res == sum) {
int x = edge[idx - 1];
edge[idx - 1] = edge[idx - 2] = 0;
s = ss, t = tt;
int res = 0, flow;
while (bfs()) {
while (flow = dinic(s, std::numeric_limits<int>::max())) res += flow;
}
cout << x + res << endl;
} else {
cout << "No Solution" << endl;
}
return 0;
}

BIN
AcWing/2189/data/11.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
AcWing/2189/data/11.in (Stored with Git LFS) Normal file

Binary file not shown.

131
AcWing/950/950.cpp Normal file
View File

@ -0,0 +1,131 @@
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
const int N = 1e5 + 5;
int n, min, k, c, ans;
char op;
// Treap
int root, cnt;
struct node {
int l, r, s, v, k;
node()
: l(0), r(0), s(0), v(0), k(rand()) {}
node(int _v)
: l(0), r(0), s(1), v(_v), k(rand()) {}
} tr[N];
void pushup(int u) {
tr[u].s = tr[tr[u].l].s + 1 + tr[tr[u].r].s;
}
std::pair<int, int> split(int p, int k) {
if (!p)
return std::make_pair(0, 0);
if (k <= tr[tr[p].l].s) {
auto o = split(tr[p].l, k);
tr[p].l = o.second;
pushup(p);
o.second = p;
return o;
}
auto o = split(tr[p].r, k - tr[tr[p].l].s - 1);
tr[p].r = o.first;
pushup(p);
o.first = p;
return o;
}
std::pair<int, int> splitByValue(int p, int v) {
if (!p)
return std::make_pair(0, 0);
if (v <= tr[p].v) {
auto o = splitByValue(tr[p].l, v);
tr[p].l = o.second;
pushup(p);
o.second = p;
return o;
}
auto o = splitByValue(tr[p].r, v);
tr[p].r = o.first;
pushup(p);
o.first = p;
return o;
}
int merge(int x, int y) {
if (!x || !y)
return x | y;
if (tr[x].k > tr[y].k) {
tr[x].r = merge(tr[x].r, y);
pushup(x);
return x;
}
tr[y].l = merge(x, tr[y].l);
pushup(y);
return y;
}
void insert(int v) {
auto o = splitByValue(root, v);
int p = ++cnt;
tr[p] = node(v);
root = merge(o.first, merge(p, o.second));
}
int getKth(int k) {
auto x = split(root, k - 1);
auto y = split(x.second, 1);
int r = y.first;
root = merge(x.first, merge(y.first, y.second));
return tr[r].v;
}
int main() {
cin >> n >> min;
while (n--) {
cin >> op >> k;
if (op == 'I') {
if (k >= min) {
insert(k - c);
}
} else if (op == 'A') {
c += k;
} else if (op == 'S') {
c -= k;
auto o = splitByValue(root, min - c);
root = o.second;
ans += tr[o.first].s;
} else { // op == 'F'
cout << (tr[root].s < k ? -1 : getKth(tr[root].s - k + 1) + c) << endl;
}
}
cout << ans << endl;
return 0;
}

46
Luogu/P8466/P8466.cpp Normal file
View File

@ -0,0 +1,46 @@
#include <iostream>
#include <algorithm>
#include <string>
using std::cin;
using std::cout;
const char endl = '\n';
int t;
std::string s;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> t;
while (t--) {
bool flag = false;
cin >> s;
std::sort(s.begin(), s.end());
if (s.find('X') != std::string::npos && s.find('D') != std::string::npos) {
flag = true;
}
int cnt = 1;
char lst = s[0];
for (int i = 1; i < s.size(); lst = s[i++]) {
if (s[i] == lst) {
cnt++;
} else {
if (cnt == 4) flag = true;
cnt = 1;
}
}
if (cnt == 4) flag = true;
cout << (flag ? "Yes" : "No") << endl;
}
return 0;
}

37
Luogu/P8467/P8467.cpp Normal file
View File

@ -0,0 +1,37 @@
#include <iostream>
#include <algorithm>
using std::cin;
using std::cout;
const char endl = '\n';
int t, a[10], p[10];
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> t;
while (t--) {
bool flag = false;
for (int i = 1; i <= 4; i++) {
cin >> a[i];
}
for (a[5] = 0; a[5] <= 9; a[5]++) {
for (int i = 1; i <= 5; i++) {
p[i] = i;
}
do {
if (a[p[1]] - 1 == a[p[2]] && a[p[2]] == a[p[3]] + 1 && a[p[4]] == a[p[5]]) flag = true;
} while (std::next_permutation(p + 1, p + 1 + 5));
}
cout << flag << endl;
}
return 0;
}

29
Luogu/P8468/P8468.cpp Normal file
View File

@ -0,0 +1,29 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
int t;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> t;
while (t--) {
long long s;
int m;
cin >> s >> m;
if (s % 2 || m == 1) {
cout << -1 << endl;
} else {
cout << 2 << ' ' << (s >> 1) << ' ' << (s >> 1) << endl;
}
}
return 0;
}

33
Luogu/P8469/P8469.cpp Normal file
View File

@ -0,0 +1,33 @@
#include <iostream>
#include <algorithm>
#include <cmath>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
int n, a[N], ans = 1;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int min = *std::min_element(a + 1, a + n + 1);
for (int i = 1; i <= n; i++) {
ans = (static_cast<long long>(ans) * static_cast<long long>(std::floor(static_cast<double>(a[i]) / min))) % mod;
}
cout << min << ' ' << ans << endl;
return 0;
}

50
Luogu/P8470/P8470.cpp Normal file
View File

@ -0,0 +1,50 @@
#include <iostream>
#include <map>
using std::cin;
using std::cout;
const char endl = '\n';
const int dx[] = {0, 1, 0, -1},
dy[] = {1, 0, -1, 0};
int n, x, y;
unsigned long long z;
std::map<int, std::map<int, unsigned long long>> map;
unsigned long long sum;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
while (n--) {
cin >> x >> y >> z;
auto cur = map[x][y]; // 当前值
for (int i = 0; i < 4; i++) {
const int xx = x + dx[i], yy = y + dy[i];
if (!map.count(xx) || !map[xx].count(yy)) continue;
auto t = map[xx][yy];
if (cur < t) {
if (cur + z >= t) {
sum -= (t - cur) * 2;
} else {
sum -= z * 2;
}
}
}
sum += z * 4; // 四个侧面
map[x][y] += z; // 更新高度
cout << sum << endl;
}
return 0;
}

108
Luogu/P8471/P8471.cpp Normal file
View File

@ -0,0 +1,108 @@
#include <iostream>
#include <algorithm>
#include <string>
using std::cin;
using std::cout;
const char endl = '\n';
int t, n, a, e;
std::string s;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> t;
while (t--) {
cin >> n >> a >> e >> s;
int cnt = std::count(s.begin(), s.end(), 'A');
if (a > cnt) {
if (a - cnt > e || (e - (a - cnt)) % 2) {
cout << -1 << endl;
} else {
int cnt1 = e - (a - cnt) >> 1,
cnt2 = (a - cnt) + (e - (a - cnt) >> 1);
for (char c : s) {
if (c == 'A') {
if (cnt1 > 0) {
cout << 'B';
cnt1--;
} else {
cout << 'A';
}
} else { // c == 'B'
if (cnt2 > 0) {
cout << 'A';
cnt2--;
} else {
cout << 'B';
}
}
}
cout << endl;
}
} else if (a == cnt) {
if (e & 1) {
cout << -1 << endl;
} else {
int cnt1 = e >> 1,
cnt2 = e >> 1;
for (char c : s) {
if (c == 'A') {
if (cnt1 > 0) {
cout << 'B';
cnt1--;
} else {
cout << 'A';
}
} else { // c == 'B'
if (cnt2 > 0) {
cout << 'A';
cnt2--;
} else {
cout << 'B';
}
}
}
cout << endl;
}
} else { // a < cnt
if (cnt - a > e || (e - (cnt - a)) % 2) {
cout << -1 << endl;
} else {
int cnt1 = (cnt - a) + (e - (cnt - a) >> 1),
cnt2 = e - (cnt - a) >> 1;
for (char c : s) {
if (c == 'A') {
if (cnt1 > 0) {
cout << 'B';
cnt1--;
} else {
cout << 'A';
}
} else { // c == 'B'
if (cnt2 > 0) {
cout << 'A';
cnt2--;
} else {
cout << 'B';
}
}
}
cout << endl;
}
}
}
return 0;
}