牛客练习赛82
牛客练习赛82
A - Mocha 的字符串
int a[N], c, ans = 2e9;
char s[N], t[] = "mocha";
bool check(int x) {
rep (i, 0, 4) if (s[i + x] ^ t[i]) return 0;
return 1;
}
int main() {
IOS; cin >> n >> k >> s + 1;
rep (i, 1, n - 4) if (check(i)) {
++c; a[m] = i; m = i;
if (c >= k) _ = a[_], umin(ans, i - _ + 5);
}
if (ans == 2e9) cout << "poor Mocha";
else cout << "Mocha suki!\n" << ans;
return 0;
}
B - Mocha 的序列
真的服气, sb的想高精去了
仔细观察操作3, 把取膜操作改作除法, 像不像
\(C_r^{r - l + 1}\) 我们当然知道这是个整数
故取膜肯定为0
int a[N];
int main() {
IOS; cin >> n >> m;
rep (i, 1, n) a[i] = i;
while (m--) {
int op, l, r, k; cin >> op >> l >> r;
if (op == 2) cin >> k;
else if (op == 3) cout << "0\n";
}
return 0;
}
C - Mocha 的二元关系
模拟即可,
先把\(b_i == b_j, i \neq j\) 且 \(c_i \neq c_j\) 的直接输出\(-1\)
然后就是挑出\(c_i == c_j, i \neq j\) 找出位置\(c_i\) 能填的数, 也就是\(b_i, b_j\) 所属集合能填的数的并集
然后又要最小, 就能求出每个数最早出现的位置, 然后贪心填数即可
const int N = 1e5 + 5;
int n, m, _, k, cas;
int c[N], b[N];
VI lis[N], g[N];
set<int> h[N], cur;
bool v[N];
int main() {
IOS; cin >> k >> n >> m;
rep (i, 1, k) { int a, b; cin >> a >> b; lis[a].pb(b); }
rep (i, 1, m) cin >> b[i];
rep (i, 1, m) {
cin >> _;
if (c[b[i]] && c[b[i]] != _) return cout << -1, 0;
c[b[i]] = _; b[i] = 0;
}
rep (i, 1, n) if (c[i]) {
for (auto &j : lis[i]) {
umax(b[j], c[i]);
if (!v[c[i]]) h[c[i]].insert(j);
else if (h[c[i]].count(j)) cur.insert(j);
}
if (v[c[i]]) h[c[i]] = cur, clear(cur);
v[c[i]] = 1;
}
rep (i, 1, n)
if (b[i]) g[b[i]].pb(i);
else cur.insert(i);
rep (i, 1, n) {
for (auto &j : g[i]) cur.insert(j);
if (!v[i]) {
if (cur.empty()) return cout << -1, 0;
b[i] = *cur.begin(), cur.erase(cur.begin());
} else {
auto it = cur.end();
for (auto &j : h[i]) if ((it = cur.find(j)) != cur.end()) break;
if (it == cur.end()) return cout << -1, 0;
b[i] = *it; cur.erase(it);
}
}
rep (i, 1, n) cout << b[i] << ' ';
return 0;
}