Codeforces Round #732 (Div. 2) A ~ D 个人题解记录
比赛链接:Here
1546A - AquaMoon and Two Arrays
选定两个数组元素执行以下操作:
-
一个 +1 另一个 -1,前提是两个数都要结果非负
请问在执行若干次后使得数组
先统计两个数组总和,只有和相同可以,否则输出 -1
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
int n; cin >> n;
int suma = 0, sumb = 0;
vector<int>a(n), b(n);
for (int &x : a)cin >> x, suma += x;
for (int &x : b)cin >> x, sumb += x;
if (suma != sumb) {
cout << "-1\n";
continue;
}
int cnt = 0;
vector<pair<int, int>>ans;
for (int i = 0; i < n; ++i)
if (a[i] > b[i])ans.push_back({i, a[i] - b[i]}), cnt += (a[i] - b[i]);
cout << cnt << "\n";
if (cnt == 0)continue;
int j = 0;
for (int i = 0; i < n; ++i) {
while (a[i] < b[i]) {
if (ans[j].second > 0) {
a[i]++;
cout << ans[j].first + 1 << " " << i + 1 << "\n";
ans[j].second--;
} else j++;
}
}
}
}
1546B - AquaMoon and Stolen String
题意都能看懂就不写了...
在每一列中,只会有一个元素出现奇数次,
只需要 map
存第
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
int n, m;
cin >> n >> m;
vector<ll>v(m, 0);
string s;
for (int i = 0; i < n; ++i) {
cin >> s;
for (int j = 0 ; j < m; ++j)
v[j] += (s[j] - 'a');
}
for (int i = 0; i < n - 1; ++i) {
cin >> s;
for (int j = 0; j < m; ++j)
v[j] -= (s[j] - 'a');
}
for (int i = 0; i < m; ++i) cout << char(v[i] + 'a');
cout << '\n';
}
}
1546C - AquaMoon and Strange Sort
对于每一个元素,肯定只能移动偶数距离
所以对于同一元素需要统计它们有多少个在奇数和偶数位置
原数组
对于每一个元素,如果它在 NO
,否则输出 YES
必须吐槽自己,大晚上写的代码不仔细,wa在 #38数据
const int N = 1e6 + 10;
int a[N], b[N], t[N][2];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
int n; cin >> n;
memset(t, 0, sizeof(t));
for (int i = 1; i <= n; ++i)cin >> a[i], b[i] = a[i];
sort(b + 1, b + 1 + n);
for (int i = 1; i <= n; ++i) {
t[a[i]][i & 1]++;
t[b[i]][i & 1]--;
}
bool f = true;
for (int i = 1; f and i <= 100000; ++i)
if (t[i][0] || t[i][1]) f = false;
cout << (f ? "YES\n" : "NO\n");
}
}
1546D - AquaMoon and Chess
看完题感觉是像某种组合数学题,但没思路
先贴一下dalao代码
#define ll long long
#define int int64_t
constexpr int N = 1e5 + 5;
constexpr int INF = 1e9 + 5;
constexpr int mod = 998244353;
int n, fac[N], invfac[N];
string s;
int carp(int x, int y) { return x * y % mod;}
int binpow(int x, int y) {
int res = 1;
for (; y; y >>= 1, x = carp(x, x))
if (y & 1) res = carp(res, x);
return res;
}
int inv(int x) { return binpow(x, mod - 2);}
void factorial() {
fac[0] = 1;
for (int i = 1; i < N; i++) fac[i] = carp(fac[i - 1], i);
invfac[N - 1] = inv(fac[N - 1]);
for (int i = N - 2; i >= 0; i--)
invfac[i] = carp(invfac[i + 1], i + 1);
}
int nCr(int m, int r) { return carp(fac[m], carp(invfac[r], invfac[m - r]));}
void solve() {
cin >> n >> s;
int z = 0, o = 0;
for (int i = 0; i < n; i++) {
int j = i;
if (s[j] == '1') {
while (j < n && s[j] == '1')
j++;
o += (j - i) / 2;
i = j - 1;
} else z++;
}
cout << nCr(z + o, o) << nl;
}
分类:
刷题笔记: CF
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· 分享4款.NET开源、免费、实用的商城系统
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 全程不用写代码,我用AI程序员写了一个飞机大战