Codeforces Round #843 (Div. 2)
https://codeforces.com/contest/1775
CD都不会写的垃圾罢了
A1. Gardener and the Capybaras (easy version)
#include <bits/stdc++.h>
using namespace std;
void solve () {
string s;
cin >> s;
for (int i = 0; i < s.size (); i++) {
for (int j = i + 1; j < s.size (); j++) {
//0,i i+1,j j+1,n
string a = s.substr (0, i + 1), b = s.substr (i + 1, j - i), c = s.substr (j + 1, s.size () - j);
if (max({a, b, c}) == b || min ({a, b, c}) == b) {
cout << a << ' ' << b << ' ' << c << endl;
return ;
}
}
}
cout << ":(" << endl;
}
int main () {
int t;
cin >> t;
while (t --) solve ();
}
//aab
//baa
//baaaa
A2. Gardener and the Capybaras (hard version)
#include <bits/stdc++.h>
using namespace std;
void solve () {
string s, a, b, c;
cin >> s;
int n = s.size ();
//max
a = s[0];
int find = -1, cntb = 0;
for (int i = 2; i < n; i++) {
if (s[i] == 'b') cntb ++;
}
for (int i = n - 1; i > 1; i--) {
if (s[i] == 'a') {
find = i;
break;
}
}
if (find == -1 || !cntb) {
b = s.substr (1, n - 2);
c = s[n - 1];
}
else {
int len1 = find - 1, len2 = n - find;
b = s.substr (1, len1), c = s.substr (find, len2);
}
if (b == max ({a, b, c})) {
cout << a << ' ' << b << ' ' << c << endl;
return ;
}
//min
int posa = -1;
for (int i = 1; i < n - 1; i++) {
if (s[i] == 'a') {
posa = i;
break;
}
}
if (posa != -1) {
for (int i = 0; i < posa; i++) cout << s[i];
cout << ' ' << s[posa] << ' ';
for (int i = posa + 1; i < n; i++) cout << s[i];
cout << endl;
return ;
}
cout << ":(" << endl;
}
int main () {
int t;
cin >> t;
while (t --) solve ();
}
//aab
//baa
//baaaa
B. Gardener and the Array
#include <bits/stdc++.h>
using namespace std;
void solve () {
int n, m, x;
cin >> n;
map<int, int> mp;
vector <int> v[n+1];
for (int i = 1; i <= n; i++) {
cin >> m;
for (int j = 1; j <= m; j++) {
cin >> x;
mp[x] ++;
v[i].push_back (x);
}
}
for (int i = 1; i <= n; i++) {
bool suc = true;
for (auto j : v[i]) {
mp[j] --;
if (mp[j] == 0) {
suc = false;
break;
}
mp[j] ++;
}
if (suc) {
cout << "Yes\n";
return ;
}
}
cout << "No\n";
}
int main () {
int t;
cin >> t;
while (t --) solve ();
}
//check相邻的两个数是否有包含关系