补题链接:Here
Proble-A. Strange Table
根据 x 确定坐标确定的行数和列数。
int main() {ios_base::sync_with_stdio(false), cin.tie(0);int _;for (cin >> _; _--;) {ll n, m, x;cin >> n >> m >> x;x--;ll col = x / n, row = x % n;cout << row * m + col + 1 << "\n";}return 0;}
Problem-B. Partial Replacement
题意:n组样例,每组单走一个字符串s,s由‘’和‘.’组成,可以把’‘号变成‘X’号,但是需要满足,首尾的‘.’号要变成‘X’号,相邻’X’距离不能超过k。求最终X个数最小值。
长度很小,直接暴搜,找到*号之后,下一个位置从x+k开始倒着找,找到最后直接返回,这样肯定是最小的了。
int main() {ios_base::sync_with_stdio(false), cin.tie(0);int _;for (cin >> _; _--;) {int n, k;string s;cin >> n >> k >> s;int cnt = 1;int i = s.find_first_of('*');while (true) {int j = min(n - 1, i + k);for (; i < j and s[j] == '.'; --j);if (i == j) break;i = j, cnt++;}cout << cnt << "\n";}return 0;}
Problem-C. Double-ended Strings
两个字符串不大,可暴力
int main() {ios_base::sync_with_stdio(false), cin.tie(0);int _;for (cin >> _; _--;) {string a, b;cin >> a >> b;int cnt = 0;int n = a.size(), m = b.size();for (int len = 1; len <= min(n, m); ++len) {for (int i = 0; i + len <= n; ++i)for (int j = 0; j + len <= m; ++j)if (a.substr(i, len) == b.substr(j, len))cnt = max(cnt, len);}cout << n + m - 2 * cnt << '\n';}return 0;}
Problem-D. Epic Transformation
这里要用一下优先队列去模拟消除的过程。
int main() {ios_base::sync_with_stdio(false), cin.tie(0);int _;for (cin >> _; _--;) {int n, x;cin >> n;map<int, int> mp;priority_queue<pair<int, int>> q;for (int i = 0; i < n; ++i) {cin >> x;mp[x]++;}for (auto [x, y] : mp) q.push({y, x});int Size = n;while (q.size() >= 2) {auto [cnt1, x1] = q.top();q.pop();auto [cnt2, x2] = q.top();q.pop();cnt1--, cnt2--, Size -= 2;if (cnt1) q.push({cnt1, x1});if (cnt2) q.push({cnt2, x2});}cout << Size << "\n";}return 0;}
Problem-E. Restoring the Permutation
E题待补…
