比赛链接:Here
1551A. Polycarp and Coins (签到)
题意:
我们有任意个面额为 和
的硬币去支付
元账单,
现在请问怎么去分配数额使得 并且要最小化
贪心,
很容易想到最小化 等于
或
int main() {cin.tie(nullptr)->sync_with_stdio(false);int _; for (cin >> _; _--;) {int n;cin >> n;if (n % 3 == 0) cout << n / 3 << " " << n / 3 << "\n";else if (n % 3 == 1) cout << n / 3 + 1 << " " << n / 3 << "\n";else cout << n / 3 << " " << n / 3 + 1 << "\n";}}
1551B1. Wonderful Coloring - 1(easy)
题意:
给定长度为 的字符串和
种颜色,
对于字符串每一个位置要么不涂颜色,要么每种颜色的字母都要不同并且最后 种颜色涂的个数相同
请输出每种颜色最后的个数
统计 26 个字母出现次数,然后出现超过 2 的+1,仅出现一次的个数 / 2即可(易证明)
int main() {cin.tie(nullptr)->sync_with_stdio(false);int _; for (cin >> _; _--;) {string s;cin >> s;int a[30] = {0};for (int i = 0; i < int(s.length()); ++i) {a[s[i] - 'a']++;}int a2 = 0, a1 = 0;for (int i = 0; i < 26; ++i) {if (a[i] == 1)a1++;if (a[i] > 1)a2++;}cout << a1 / 2 + a2 << "\n";}}
1551B2. Wonderful Coloring - 2 (hard版本)
题意基本同 B1 一致,
但需输出每个位置数字涂的颜色
写了两罚模拟 #card=math&code=%5Cmathcal%7BO%7D%28n%5E2%29) 不出所料肯定 T了,
转换一下思路,首先和 B1 一样我们需要去统计每种数字的个数,但由于最后需要输出每个位置的颜色编号,所以还得存一下下标 (pos)
的将下标存储
无需使用标
当然对于多余的元素,可以直接从删除
while (pos.size() % k != 0)pos.pop_back();
此时 pos 中所有元素均为有效下标,我们只要对应原数组标记颜色编号即可
int main() {cin.tie(nullptr)->sync_with_stdio(false);int _; for (cin >> _; _--;) {int n, k;cin >> n >> k;vector<int>a(n), cnt(n);vector<int>pos;for (int i = 0; i < n; ++i) {cin >> a[i], a[i] -= 1;cnt[a[i]] += 1;if (cnt[a[i]] <= k) pos.push_back(i);}while (pos.size() % k != 0)pos.pop_back();sort(pos.begin(), pos.end(), [&](int i, int j) {return a[i] < a[j];});vector<int>ans(n);for (int i = 0; i < pos.size(); ++i)ans[pos[i]] = i % k + 1;for (int i = 0; i < n; ++i)cout << ans[i] << " \n"[i == n - 1];}}
1551C. Interesting Story
题意:
一个作家有 个单词,每一个单词只会由
a,b,c,d,e 构成,他想用 #card=math&code=m%280%5Cle%20m%5Cle%20n%29) 个单词写一个故事
一个故事是否有趣在于:
- 故事中存在一个字母的个数比其他字母个数的总和还更多
比如:bac,aaada,e三个单词,a出现的次数比其他 4 种单词出现次数都多
请输出在保证故事有趣的情况下用更多的单词写故事
这里建议直接看代码便于理解
【AC Code】代码参考于比赛 高Rank dalao
int main() {cin.tie(nullptr)->sync_with_stdio(false);int _; for (cin >> _; _--;) {int n;cin >> n;vector<string>s(n);for (int i = 0; i < n; ++i) cin >> s[i];int ans = 0;for (int c = 0; c < 5; ++c) {vector<int>f(n);for (int i = 0; i < n; ++i) {for (auto x : s[i])if (x == 'a' + c)f[i]++;else f[i]--;}sort(f.begin(), f.end(), greater<int>());int sum = 0;for (int i = 0; i < n; ++i) {sum += f[i];if (sum <= 0)break;ans = max(ans, i + 1);}}cout << ans << "\n";}}
很好奇自己是怎么读题读成使用连续的单词去写故事的啊?kola
1551D1. Domino (easy version)
题意:待补
多米诺骨牌的排放似乎在ABC的某一场也出现过
如果 为奇数
- 最少要横放
个,不然最少
个
- 最多
#card=math&code=n%20%2A%20m%20%2F%202%20%3D%20%28m%20%5C%25%202%20%3D%3D%201%20%3F%5C%20n%20%2F%202%20%3A%200%29) 个
对于给出的 只要在
就输出
YES
int main() {cin.tie(nullptr)->sync_with_stdio(false);int _; for (cin >> _; _--;) {int n, m, k;cin >> n >> m >> k;int mn = (n % 2 == 1 ? m / 2 : 0);int mx = n * m / 2 - (m % 2 == 1 ? n / 2 : 0);if (mn <= k and k <= mx and (k - mn) % 2 == 0) cout << "YES\n";else cout << "NO\n";}}
