A All-Star Game
B Bon Voyage
C Cinema
D Disgusting Relationship
E Enigmatic Partition
F Factorio
G. Game SET
#include
using namespace std;
const int N = 1e6 + 10;
int n;
string str[13] = {
"one", "two", "three",
"diamond", "squiggle", "oval",
"solid", "striped", "open",
"red", "green", "purple",
"*"
};
map<string, int> mp;
bool check(int a, int b, int c) {
if (a == 4) {
if (b == 4) {
// 就看c
return true;
} else {
// b!=c 就构造a!=b!=c
// b==c 就构造a==b==c
return true;
}
} else {
if (b == 4) {
//构造a!=b!=c
return true;
} else {
if (c == 4) {
//构造a!=b!=c
return true;
} else {
return (a == b && b == c) || (a != b && b != c && a != c);
}
}
}
}
int a[N][4];
void getId(string s, int id) {
for (int i = 0, j = 0, st, sz = s.length(); i < sz; i++) {
if (s[i] == '[') {
st = i + 1;
while (s[++i] != ']');
a[id][j++] = mp[s.substr(st, i - st)];
}
}
}
string s;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
mp[str[0]] = 1; mp[str[1]] = 2; mp[str[2]] = 3;
mp[str[3]] = 1; mp[str[4]] = 2; mp[str[5]] = 3;
mp[str[6]] = 1; mp[str[7]] = 2; mp[str[8]] = 3;
mp[str[9]] = 1; mp[str[10]] = 2; mp[str[11]] = 3;
mp[str[12]] = 4;
int T;
cin >> T;
for (int cs = 1; cs <= T; cs++) {
cout << "Case #" << cs << ": ";
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> s;
getId(s, i);
}
int f1 = 0;
// 显然 个数达到一定程度 肯定有解
// 最多33^3 就能找到答案
for (int i = 1, lim = min(33, n); i <= lim; i++) {
for (int j = i + 1; j <= lim; j++) {
for (int l = j + 1; l <= lim; l++) {
int f2 = 1;
for (int k = 0; k < 4; k++) {
if (!check(a[i][k], a[j][k], a[l][k])) {
f2 = 0;
break;
}
}
if (f2) {
f1 = 1;
cout << i << " " << j << " " << l << endl;
break;
}
}
if (f1) break;
}
if (f1) break;
}
if (!f1) {
cout << -1 << endl;
}
}
return 0;
}
H Hard String Problem
总结: 10 10 10 组 3 e 5 3e5 3e5 的建图不适合网络流(要么趁出题人数据水时蒙个优化)
#include
using namespace std;
const int N = 1e6 + 10;
int n;
namespace Discretization {
vector<int> backUp;
void discrete() {
sort(backUp.begin(), backUp.end());
backUp.erase(unique(backUp.begin(), backUp.end()), backUp.end());
}
int id(int x) {
return lower_bound(backUp.begin(), backUp.end(), x) - backUp.begin() + 1;
}
}
using namespace Discretization;
namespace Union_Find { // 并查集板子
int sz[N], e_sz[N];
int fa[N];
int find(int x) {
return fa[x] == x ? x : fa[x] = find(fa[x]);
}
void Union(int x, int y) {
int fx = find(x);
int fy = find(y);
if (fx == fy) {
e_sz[fx]++;
return;
}
if (fx < fy) {
fa[fy] = fx;
sz[fx] += sz[fy];
sz[fy] = 0;
e_sz[fx] += e_sz[fy] + 1;
} else {
fa[fx] = fy;
sz[fy] += sz[fx];
sz[fx] = 0;
e_sz[fy] += e_sz[fx] + 1;
}
}
}
using namespace Union_Find;
int a[N], b[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
for (int cs = 1; cs <= T; cs++) {
cout << "Case #" << cs << ": ";
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
backUp.push_back(a[i]);
backUp.push_back(b[i]);
}
discrete();//离散化
for (int i = 1, _sz = backUp.size(); i <= _sz; i++) {
fa[i] = i;
sz[i] = 1;
e_sz[i] = 0;
}
for (int i = 1; i <= n; i++) {
a[i] = id(a[i]);
b[i] = id(b[i]);
Union(a[i], b[i]);
}
int res = 0;
for (int i = 1, _sz = backUp.size(); i <= _sz; i++) {
if (i == find(i)) {
res += min(sz[i], e_sz[i]);
}
}
cout << res << endl;
backUp.clear();
}
return 0;
}
J Jumping Points
#include
using namespace std;
typedef __int128 ll;
const int N = 1e5 + 10;
int a[N], b[N], Minb[N];
ll sum[N], Mx[N];
int n;
ll max(ll x, ll y) {
return x >= y ? x : y;
}
void _print(ll x) {
if (x > 9) _print(x / 10);
putchar(x % 10 + '0');
}
void print(ll x) {//输出
if (x < 0) {
x = -x;
putchar('-');
}
_print(x);
puts("");
}
pair<ll, int> mp[N];
int tot = 0;
int main() {
int T;
scanf("%d", &T);
for (int cs = 1; cs <= T; cs++) {
printf("Case #%d: ", cs);
scanf("%d", &n);
tot = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= n; i++) {
scanf("%d", &b[i]);
sum[i] = sum[i - 1] + a[i];
if (i == 1) {
Mx[i] = sum[i];
Minb[i] = b[i];
} else {
Mx[i] = max(Mx[i - 1], sum[i]);
Minb[i] = min(Minb[i - 1], b[i]);
}
if (Mx[i] == sum[i]) {
mp[++tot] = {Mx[i], Minb[i]};
}
}
int cnt = 0, x;//cnt 当前已经接待了多少游客
ll res = 0;
for (int i = tot; i > 0; i--) {
x = max(0, mp[i].second - cnt);
res += mp[i].first * x;
cnt += x;
}
printf("%d ", b[1]);
print(res);
}
return 0;
}