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

Compare commits

..

No commits in common. "83d0904c97b1b0d753cdd752f0009904570bb684" and "746fe02ec039061c92f0f9eec15a92b8eee0ea1e" have entirely different histories.

10 changed files with 0 additions and 568 deletions

View File

@ -1,128 +0,0 @@
#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)

Binary file not shown.

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

Binary file not shown.

View File

@ -1,131 +0,0 @@
#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;
}

View File

@ -1,46 +0,0 @@
#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;
}

View File

@ -1,37 +0,0 @@
#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;
}

View File

@ -1,29 +0,0 @@
#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;
}

View File

@ -1,33 +0,0 @@
#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;
}

View File

@ -1,50 +0,0 @@
#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;
}

View File

@ -1,108 +0,0 @@
#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;
}