比赛链接:Here


1546A - AquaMoon and Two Arrays

选定两个数组元素执行以下操作:

  • \(a_i,a_j (1\le i,j \le n)\) 一个 +1 另一个 -1,

    前提是两个数都要结果非负

请问在执行若干次后使得数组 \(a\) 等于 数组 \(b\)


先统计两个数组总和,只有和相同可以,否则输出 -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 存第 \(i\) 位的值即可

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

对于每一个元素,肯定只能移动偶数距离

所以对于同一元素需要统计它们有多少个在奇数和偶数位置

原数组 \(a\) ,排序后数组 \(b\)

对于每一个元素,如果它在 \(a\) 中的奇数位置次数不同于在 \(b\) 中奇数位置出现次数(偶数同理)则输出 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;
}

Codeforces Round #732 (Div. 2) A ~ D 个人题解记录的更多相关文章

  1. Codeforces Round #609 (Div. 2)前五题题解

    Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...

  2. Codeforces Round #732 (Div. 2)【ABCD】

    比赛链接:https://codeforces.com/contest/1546 A. AquaMoon and Two Arrays 题意 给出两个大小为 \(n\) 的数组 \(a, b\) ,每 ...

  3. Codeforces Round #732 (Div.1) 题解

    实在是打击人信心的一场比赛啊--一不注意就掉了 50+ 分,rating 没了啊/ll/dk/wq/kk A Weak pretest!!!!!11 /fn/fn/fn 一个很显然的注意点是在交换前后 ...

  4. Codeforces Round #556 (Div. 2) D. Three Religions 题解 动态规划

    题目链接:http://codeforces.com/contest/1150/problem/D 题目大意: 你有一个参考串 s 和三个装载字符串的容器 vec[0..2] ,然后还有 q 次操作, ...

  5. Codeforces Round #604 (Div. 2) E. Beautiful Mirrors 题解 组合数学

    题目链接:https://codeforces.com/contest/1265/problem/E 题目大意: 有 \(n\) 个步骤,第 \(i\) 个步骤成功的概率是 \(P_i\) ,每一步只 ...

  6. Codeforces Round #624 (Div. 3) F. Moving Points 题解

    第一次写博客 ,请多指教! 翻了翻前面的题解发现都是用树状数组来做,这里更新一个 线段树+离散化的做法: 其实这道题是没有必要用线段树的,树状数组就能够解决.但是个人感觉把线段树用熟了会比树状数组更有 ...

  7. Codeforces Round #677 (Div. 3) E、G题解

    E. Two Round Dances #圆排列 题目链接 题意 \(n\)(保证偶数)个人,要表演一个节目,这个节目包含两种圆形舞蹈,而每种圆形舞蹈恰好需要\(n/2\)个人,每个人只能跳一种圆形舞 ...

  8. Codeforces Round#402(Div.1)掉分记+题解

    哎,今天第一次打div1 感觉头脑很不清醒... 看到第一题就蒙了,想了好久,怎么乱dp,倒过来插之类的...突然发现不就是一道sb二分吗.....sb二分看了二十分钟........ 然后第二题看了 ...

  9. Codeforces Round #436 (Div. 2) E. Fire(dp 记录路径)

    E. Fire time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...

  10. Codeforces Round #436 (Div. 2) E. Fire(背包+记录路径)

    传送门 题意 给出n种物品,抢救第\(i\)种物品花费时间\(t_i\),价值\(p_i\),截止时间\(d_i\) 询问抢救的顺序及物品价值和最大值 分析 按\(d_i\)排序的目的是防止以下情况 ...

随机推荐

  1. Vue + Element UI 实现复制当前行数据功能(复制到新增页面组件值不能更新等问题解决)

    1.需求 使用Vue + Element UI 实现在列表的操作栏新增一个复制按钮,复制当前行的数据可以打开新增弹窗后亦可以跳转到新增页面,本文实现为跳转到新增页面. 2.实现 1)列表页 index ...

  2. WPF 绑定binding都有哪些事件

    在WPF中,源属性(Source Property)指的是提供数据的属性,通常是数据模型或者其他控件的属性,而目标属性(Target Property)则是数据绑定的目标,通常是绑定到控件的属性,例如 ...

  3. [ARC156C] Tree and LCS

    Problem Statement We have a tree $T$ with vertices numbered $1$ to $N$. The $i$-th edge of $T$ conne ...

  4. Scrapy-settings.py常规配置

    # Scrapy settings for scrapy_demo project # # For simplicity, this file contains only settings consi ...

  5. 华企盾DSC使用outlook发送加密文件提示解密插件未加载

    1.如果是非exchange邮箱,不能勾选"启用邮件白名单outlook插件(exchange邮箱建议勾选)"​ 2.如果是exchange邮箱则需要勾选"启用邮件白名单 ...

  6. 关于`dial unix /var/run/docker.sock: connect: permission denied`的处理方法笔记

    之前遇到的一个问题,使用非root用户时操作docker提示无权限,在查阅了一些文章之后自己又摸索出了一些更方便的方法,顺手记录下来. 一.问题发现 根据报错信息dial unix /var/run/ ...

  7. Windows Server 2008 R2 & Windows Server 2012 R2 无法通过update更新的解决方法

    windows Server 2008 r2 无法通过update更新的解决方法 注意:目前windows Server系列操作系统已经完全停止支持. 1.安装 SP1补丁 KB976932 点击:微 ...

  8. 为什么说UUID是唯一的?

    在数字时代,我们需要一种能够唯一标识各种实体的方法.通用唯一标识符(UUID)正是为满足这一需求而诞生的.本文将从多个方面介绍UUID,探讨它为何成为通用唯一标识符,以及为什么说UUID是唯一的. U ...

  9. 小乌龟(TortoiseGit)配置SSH

    小乌龟(TortoiseGit)配置SSH 使用gerrit作为项目管理,使用console窗口命令,我真是不记得太多git命令,因此交给小乌龟可视化操作,简单方便.这里记录下配置SSH公钥私钥. 前 ...

  10. win10安装WSL

    一.什么是WSL? Windows Subsystem for Linux 简称 WSL,是一个在Windows 10上能够运行原生Linux二进制可执行文件(ELF格式)的兼容层. 二.如何安装WS ...