0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-10 22:38:48 +00:00

Compare commits

..

3 Commits

75 changed files with 493 additions and 0 deletions

134
S2OJ/1494/1494.cpp Normal file
View File

@ -0,0 +1,134 @@
#include <iostream>
#include <algorithm>
#include <limits>
#include <queue>
#include <tuple>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e6 + 5;
int n, s, t, f[N], ans;
std::tuple<int, int, int> points[N];
int idx, head[N << 1], ver[N << 2], edge[N << 2], next[N << 2];
int cur[N << 1], dist[N << 1];
void add(int u, int v, int w) {
next[idx] = head[u];
ver[idx] = v;
edge[idx] = w;
head[u] = idx++;
}
bool bfs() {
std::fill_n(dist, N << 1, 0);
std::queue<int> q;
q.push(s);
dist[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 (w && !dist[v]) {
dist[v] = dist[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 (dist[v] == dist[u] + 1 && w) {
int k = dinic(v, std::min(w, limit - flow));
if (!k) {
dist[v] = 0;
} else {
flow += k;
edge[i] -= k;
edge[i ^ 1] += k;
}
}
}
return flow;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
std::fill_n(head, N << 1, -1);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> std::get<0>(points[i]) >> std::get<1>(points[i]) >> std::get<2>(points[i]);
}
std::sort(points + 1, points + 1 + n);
for (int i = 1; i <= n; i++) {
f[i] = 1;
for (int j = 1; j < i; j++) {
int x1, y1, z1,
x2, y2, z2;
std::tie(x1, y1, z1) = points[i];
std::tie(x2, y2, z2) = points[j];
if (x2 < x1 && y2 < y1 && z2 < z1) {
f[i] = std::max(f[i], f[j] + 1);
add(j, i + n, 1);
add(i + n, j, 0);
}
}
ans = std::max(ans, f[i]);
}
s = n * 2 + 1, t = s + 1;
for (int i = 1; i <= n; i++) {
add(s, i, 1);
add(i, s, 0);
add(i + n, t, 1);
add(t, i + n, 0);
}
int res = 0, flow;
while (bfs()) {
while (flow = dinic(s, std::numeric_limits<int>::max())) res += flow;
}
cout << ans << endl
<< n - res << endl;
return 0;
}

BIN
S2OJ/1494/data/data1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1494/data/data1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1494/data/data10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1494/data/data10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1494/data/data2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1494/data/data2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1494/data/data3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1494/data/data3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1494/data/data4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1494/data/data4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1494/data/data5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1494/data/data5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1494/data/data6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1494/data/data6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1494/data/data7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1494/data/data7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1494/data/data8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1494/data/data8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1494/data/data9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1494/data/data9.out (Stored with Git LFS) Normal file

Binary file not shown.

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

Binary file not shown.

106
S2OJ/1496/1496.cpp Normal file
View File

@ -0,0 +1,106 @@
#include <iostream>
#include <algorithm>
#include <string>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 15;
int n, t, a[N << 2], b[N << 2];
bool check() {
int cnt = 0;
for (int i = 1; i <= 27; i++) {
if (b[i] < 0) return false;
if (b[i] >= 3) {
b[i] -= 3;
cnt++;
}
if (i % 9 == 0 || i % 9 == 8) continue;
while (b[i] > 0) {
b[i]--, b[i + 1]--, b[i + 2]--;
cnt++;
}
}
return cnt == 4;
}
bool check_hu() {
bool flag = false;
for (int i = 1; i <= 27; i++) {
if (a[i] >= 2) flag = true;
}
if (!flag) return false;
for (int i = 1; i <= 27; i++) {
if (a[i] < 2) continue;
std::copy_n(a, N << 2, b);
b[i] -= 2;
if (check()) return true;
}
return false;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> t;
while (t--) {
std::fill_n(a, N << 2, 0);
for (int i = 1; i <= n; i++) {
std::string s;
cin >> s;
int x = s[0] - '0';
char c = s[1];
if (c == 'p') x += 9;
else if (c == 's') x += 18;
a[x]++;
}
if (n == 14) {
cout << check_hu() << endl;
} else { // n == 13
for (int i = 1; i <= 27; i++) {
if (a[i] < 4) {
a[i]++;
if (check_hu()) {
cout << (i - 1) % 9 + 1;
if (1 <= i && i <= 9) {
cout << "m ";
} else if (10 <= i && i <= 18) {
cout << "p ";
} else { // 19 <= i && i <= 27
cout << "s ";
}
}
a[i]--;
}
}
cout << endl;
}
}
return 0;
}

BIN
S2OJ/1496/data/data1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data11.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data12.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data12.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data13.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data13.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data14.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data14.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data15.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data15.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data16.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data16.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data17.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data17.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data18.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data18.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data19.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data19.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data20.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data20.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data21.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data21.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data22.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data22.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data23.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data23.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data24.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data24.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data25.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data25.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1496/data/data9.out (Stored with Git LFS) Normal file

Binary file not shown.

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

Binary file not shown.

37
utils/graph.h Normal file
View File

@ -0,0 +1,37 @@
#include <tuple>
#include <vector>
template <typename T>
class Graph {
private:
// Indexes of the first edge of each vertex.
std::vector<std::size_t> head;
// Edges of the graph.
// Elements in a std::tuple are <to, weight, next>
std::vector<std::tuple<std::size_t, T, std::size_t>> edge;
public:
Graph() = default;
Graph(const int &_n)
: head(n, -1) {}
// Add an edge from u to v with weight w.
void add(const std::size_t &_u, const std::size_t &_v, const T &_w) {
edge.emplace_back(_v, _w, head[_u]);
head[_u] = edge.size() - 1;
}
// Add an undirected edge from u to v with weight `w`.
void add_undirected(const std::size_t &_u, const std::size_t &_v, const T &_w) {
add(_u, _v, _w);
add(_v, _u, _w);
}
// Add an undirected edge from u to v with weight `w`, specifies the weight `rw` of reverse edge.
void add_undirected(const std::size_t &_u, const std::size_t &_v, const T &_w, const T &_rw) {
add(_u, _v, _w);
add(_v, _u, _rw);
}
};