标签:ble 前缀 strlen ret amp c++ cin 奇数 --
找到个位置对称位置 != ‘a‘ 即可, 找不到且全串不为 ‘a‘, 直接放最后
int n, m, _, k, cas;
char s[N];
int main() {
IOS;
for (cin >> _; _; --_) {
cin >> s + 1; n = strlen(s + 1);
bool f = 1; m = n;
rep (i, 1, n) if (s[i] ^ ‘a‘) f = 0;
if (f) { cout << "NO\n"; continue; }
cout << "YES\n";
rep (i, 1, n >> 1) if (s[n + 1 - i] ^ ‘a‘) m = i;
rep (i, 1, n) {
if (m == i) cout << ‘a‘;
cout << s[i];
}
cout << ‘\n‘;
}
return 0;
}
倒序修改每个位置, 则要保证每个位置的前缀 0, 1 为偶数即可
int c[N];
char a[N], b[N];
int main() {
IOS;
for (cin >> _; _; --_) {
cin >> n >> a + 1 >> b + 1;
rep (i, 1, n) c[i] = 0; bool f = 1, g = 1;
rep (i, 1, n) c[i] += c[i - 1] + (a[i] ^ ‘1‘);
per (i, n, 1) if (g ^ (a[i] == b[i])) {
if ((i & 1) || c[i] != i >> 1) f = 0;
g ^= 1;
}
cout << (f ? "YES\n" : "NO\n");
}
return 0;
}
因为1相同, 0不相同, 故 0, 1数都为偶数, 且都是对于a来说, 一般是‘(‘
故模拟即可, 当不合法时, 直接break
char s[N], a[N], b[N];
int main() {
IOS;
for (cin >> _; _; --_) {
cin >> n >> s + 1; bool f = 1; int x = 0, y = 0, c = 0;
rep (i, 1, n) if (s[i] == ‘1‘) ++c;
if (c & 1) { cout << "NO\n"; continue; }
rep (i, 1, n) {
if (s[i] == ‘1‘) {
if (c) a[i] = b[i] = ‘(‘, c -= 2, ++x, ++y;
else a[i] = b[i] = ‘)‘, --x, --y;
} else {
if (x >= y) a[i] = ‘)‘, b[i] = ‘(‘, --x, ++y;
else a[i] = ‘(‘, b[i] = ‘)‘, ++x, --y;
}
if (x < 0 || y < 0) { f = 0; break; }
}
if (!f) { cout << "NO\n"; continue; }
a[n + 1] = b[n + 1] = ‘\0‘;
cout << "YES\n" << a + 1 << ‘\n‘ << b + 1 << ‘\n‘;
}
return 0;
}
先想没有禁手, 那毫无疑问用两种数即可, 分奇偶填不就完了?
有了禁手, 多了个颜色3, 那就再把所有 奇数/偶数 格子填完之后, 要么填 2/1 , 要么填 3 即可
vector<PII> a[2];
int main() {
IOS; cin >> n;
rep (i, 1, n) rep (j, 1, n) a[i + j & 1].pb(i, j);
rep(_, 1, n * n) {
cin >> k;
if (k != 2 && !a[1].empty()) cout << 2 << ‘ ‘ << a[1].back().fi << ‘ ‘ << a[1].back().se << endl, a[1].pop_back();
else if (k != 1 && !a[0].empty()) cout << 1 << ‘ ‘ << a[0].back().fi << ‘ ‘ << a[0].back().se << endl, a[0].pop_back();
else if (!a[1].empty()) cout << 3 << ‘ ‘ << a[1].back().fi << ‘ ‘ << a[1].back().se << endl, a[1].pop_back();
else cout << 3 << ‘ ‘ << a[0].back().fi << ‘ ‘ << a[0].back().se << endl, a[0].pop_back();
}
return 0;
}
Codeforces Round #712 (Div. 2)
标签:ble 前缀 strlen ret amp c++ cin 奇数 --
原文地址:https://www.cnblogs.com/2aptx4869/p/14615677.html