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

Compare commits

...

7 Commits

139 changed files with 878 additions and 11 deletions

84
LibreOJ/187/187.cpp Normal file
View File

@ -0,0 +1,84 @@
#include <iostream>
#include <cstring>
#include <queue>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 105,
K = 12;
const int INF = 0x3f3f3f3f;
int n, m, k, a[K], f[1 << K][N], ans = INF;
std::vector<std::pair<int, int>> g[N];
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> k;
for (int i = 1, u, v, w; i <= m; i++) {
cin >> u >> v >> w;
g[u].emplace_back(v, w);
g[v].emplace_back(u, w);
}
memset(f, 0x3f, sizeof(f));
for (int i = 1; i <= k; i++) {
cin >> a[i];
f[1 << (i - 1)][a[i]] = 0;
}
for (int s = 0; s < 1 << k; s++) {
std::queue<int> q;
std::vector<bool> vis(n + 1);
for (int i = 1; i <= n; i++) {
for (int t = s & (s - 1); t; t = (t - 1) & s) {
f[s][i] = std::min(f[s][i], f[t][i] + f[s ^ t][i]);
}
if (f[s][i] != INF) {
q.emplace(i);
vis[i] = true;
}
}
// SPFA
while (!q.empty()) {
int u = q.front();
q.pop();
vis[u] = false;
for (auto e : g[u]) {
int v = e.first,
w = e.second;
if (f[s][v] > f[s][u] + w) {
f[s][v] = f[s][u] + w;
if (!vis[v]) {
q.emplace(v);
vis[v] = true;
}
}
}
}
}
for (int i = 1; i <= k; i++) {
ans = std::min(ans, f[(1 << k) - 1][a[i]]);
}
cout << ans << endl;
return 0;
}

BIN
LibreOJ/187/data/graph1.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/187/data/graph1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/187/data/graph10.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/187/data/graph10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/187/data/graph2.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/187/data/graph2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/187/data/graph3.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/187/data/graph3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/187/data/graph4.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/187/data/graph4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/187/data/graph5.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/187/data/graph5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/187/data/graph6.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/187/data/graph6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/187/data/graph7.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/187/data/graph7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/187/data/graph8.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/187/data/graph8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/187/data/graph9.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/187/data/graph9.in (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -1,5 +1,6 @@
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
using std::cin;
@ -16,12 +17,16 @@ struct node {
int l, r, c;
} tr[N << 5];
int find(int x) {
return std::distance(nums.begin(), std::lower_bound(nums.begin(), nums.end(), x));
}
int build(int l, int r) {
int p = ++cnt;
if (l == r) return p;
int mid = l + r >> 1;
int mid = (l + r) >> 1;
tr[p].l = build(l, mid);
tr[p].r = build(mid + 1, r);
@ -31,30 +36,35 @@ int build(int l, int r) {
int insert(int p, int l, int r, int x) {
int q = ++cnt;
tr[q] = tr[p];
if (l == r) {
tr[q].c++;
return q;
}
int mid = l + r >> 1;
int mid = (l + r) >> 1;
if (x <= mid) tr[q].l = insert(tr[q].l, l, mid, x);
else tr[q].r = insert(tr[q].r, mid + 1, r, x);
if (x <= mid) tr[q].l = insert(tr[p].l, l, mid, x);
else tr[q].r = insert(tr[p].r, mid + 1, r, x);
tr[q].c = tr[tr[q].l].c + tr[tr[q].r].c;
return q;
}
int query(int p, int q, int l, int r, int x) {
int query(int p, int q, int l, int r, int k) {
if (l == r) return l;
int c = tr[tr[p].l].c - tr[tr[q].l].c;
int mid = l + r >> 1;
if (x <= c) return query(tr[p].l, tr[q].l, l, mid, x);
return query(tr[p].r, tr[q].r, mid + 1, r, x - c);
int mid = (l + r) >> 1;
int c = tr[tr[q].l].c - tr[tr[p].l].c;
if (c >= k) return query(tr[p].l, tr[q].l, l, mid, k);
return query(tr[p].r, tr[q].r, mid + 1, r, k - c);
}
int main() {
@ -75,7 +85,7 @@ int main() {
root[0] = build(0, nums.size() - 1);
for (int i = 1; i <= n; i++) {
root[i] = insert(root[i - 1], 0, nums.size() - 1, std::lower_bound(nums.begin(), nums.end(), a[i]) - nums.begin());
root[i] = insert(root[i - 1], 0, nums.size() - 1, find(a[i]));
}
while (m--) {
@ -83,7 +93,7 @@ int main() {
cin >> l >> r >> k;
cout << nums.at(query(root[r], root[l - 1], 0, nums.size() - 1, k)) << endl;
cout << nums[query(root[l - 1], root[r], 0, nums.size() - 1, k)] << endl;
}
return 0;

26
Luogu/P4549/P4549.cpp Normal file
View File

@ -0,0 +1,26 @@
#include <iostream>
#include <cmath>
#include <experimental/numeric>
using std::cin;
using std::cout;
const char endl = '\n';
int n, ans;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1, x; i <= n; i++) {
cin >> x;
ans = std::experimental::gcd(ans, std::abs(x));
}
cout << ans << endl;
return 0;
}

162
Luogu/P5192/P5192.cpp Normal file
View File

@ -0,0 +1,162 @@
#include <iostream>
#include <algorithm>
#include <iterator>
#include <queue>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 2e5 + 5,
M = 2e6 + 5;
const int INF = 0x3f3f3f3f;
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() {
std::fill(std::begin(d), std::end(d), 0);
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]) {
cur[u] = 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);
while (cin >> n >> m) {
idx = 0;
std::fill(std::begin(head), std::end(head), -1);
std::fill(std::begin(f), std::end(f), 0);
ss = 0, tt = n + m + 1;
for (int i = 1, x; i <= m; i++) {
cin >> x;
add(ss, i, INF - x);
add(i, ss, 0);
f[ss] -= x;
f[i] += x;
}
for (int i = 1, c, d; i <= n; i++) {
cin >> c >> d;
add(m + i, tt, d);
add(tt, m + i, 0);
for (int j = 1, t, l, r; j <= c; j++) {
cin >> t >> l >> r;
t++;
add(t, m + i, r - l);
add(m + i, t, 0);
f[t] -= l;
f[m + i] += l;
}
}
int sum = 0;
s = n + m + 2, t = n + m + 3;
for (int i = 0; i <= n + m + 1; 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, INF);
add(ss, tt, 0);
int res = 0;
while (bfs()) {
while (int flow = dinic(s, INF)) res += flow;
}
if (res == sum) {
int x = edge[idx - 1];
edge[idx - 1] = edge[idx - 2] = 0;
s = ss, t = tt;
int res = 0;
while (bfs()) {
while (int flow = dinic(s, INF)) res += flow;
}
cout << x + res << endl;
} else {
cout << -1 << endl;
}
cout << endl;
}
return 0;
}

45
S2OJ/1272/1272.cpp Normal file
View File

@ -0,0 +1,45 @@
#include <iostream>
#include <algorithm>
#include <string>
#include <unordered_map>
using std::cin;
using std::cout;
const char endl = '\n';
void solve() {
int n;
bool flag = false;
std::unordered_map<std::string, bool> map, map2;
cin >> n;
for (int i = 1; i <= n; i++) {
std::string s;
cin >> s;
map[s] = true;
if (s.size() > 1) map2[s.substr(0, s.size() - 1)] = true;
std::reverse(s.begin(), s.end());
if (map.count(s) || map2.count(s)) flag = true;
if (s.size() > 1 && map.count(s.substr(0, s.size() - 1))) flag = true;
}
cout << (flag ? "YES" : "NO") << endl;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) solve();
return 0;
}

BIN
S2OJ/1272/data/ex_palindrome1.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/ex_palindrome1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome1.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome10.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome11.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome12.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome12.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome13.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome13.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome14.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome14.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome15.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome15.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome16.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome16.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome17.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome17.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome18.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome18.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome19.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome19.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome2.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome20.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome20.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome3.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome4.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome5.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome6.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome7.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome8.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome9.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1272/data/palindrome9.in (Stored with Git LFS) Normal file

Binary file not shown.

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

Binary file not shown.

60
S2OJ/1320/1320.cpp Normal file
View File

@ -0,0 +1,60 @@
#include <iostream>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
std::string s, t;
std::vector<std::pair<int, int>> ans;
bool check() {
if (std::count(s.begin(), s.end(), '1') != std::count(t.begin(), t.end(), '1')) {
return false;
}
for (int i = 0; i < s.size(); i++) {
if (s[i] == t[i]) continue;
int cnt = 0;
bool flag = false;
for (int j = i; j < s.size(); j++) {
if (s[j] == '1') cnt++;
if (s[j] == t[i] && cnt % 2 == 0) {
flag = true;
ans.emplace_back(i + 1, j + 1);
std::reverse(s.begin() + i, s.begin() + j + 1);
break;
}
}
if (!flag) return false;
}
return true;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> s >> t;
if (check()) {
cout << "YES" << endl
<< ans.size() << endl;
for (auto e : ans) {
cout << e.first << ' ' << e.second << endl;
}
} else {
cout << "NO" << endl;
}
return 0;
}

BIN
S2OJ/1320/data/chk.cpp (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/ex_rev1.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/ex_rev1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/ex_rev2.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/ex_rev2.in (Stored with Git LFS) Normal file

Binary file not shown.

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

Binary file not shown.

BIN
S2OJ/1320/data/rev1.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/rev1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/rev10.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/rev10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/rev11.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/rev11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/rev12.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/rev12.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/rev13.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/rev13.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/rev14.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/rev14.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/rev15.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/rev15.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/rev16.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/rev16.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/rev17.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/rev17.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/rev18.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/rev18.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/rev19.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/rev19.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/rev2.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/rev2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1320/data/rev20.ans (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