Codeforces Round #732 (Div. 2) A ~ D 个人题解记录
比赛链接: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 个人题解记录的更多相关文章
- Codeforces Round #609 (Div. 2)前五题题解
Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...
- Codeforces Round #732 (Div. 2)【ABCD】
比赛链接:https://codeforces.com/contest/1546 A. AquaMoon and Two Arrays 题意 给出两个大小为 \(n\) 的数组 \(a, b\) ,每 ...
- Codeforces Round #732 (Div.1) 题解
实在是打击人信心的一场比赛啊--一不注意就掉了 50+ 分,rating 没了啊/ll/dk/wq/kk A Weak pretest!!!!!11 /fn/fn/fn 一个很显然的注意点是在交换前后 ...
- Codeforces Round #556 (Div. 2) D. Three Religions 题解 动态规划
题目链接:http://codeforces.com/contest/1150/problem/D 题目大意: 你有一个参考串 s 和三个装载字符串的容器 vec[0..2] ,然后还有 q 次操作, ...
- Codeforces Round #604 (Div. 2) E. Beautiful Mirrors 题解 组合数学
题目链接:https://codeforces.com/contest/1265/problem/E 题目大意: 有 \(n\) 个步骤,第 \(i\) 个步骤成功的概率是 \(P_i\) ,每一步只 ...
- Codeforces Round #624 (Div. 3) F. Moving Points 题解
第一次写博客 ,请多指教! 翻了翻前面的题解发现都是用树状数组来做,这里更新一个 线段树+离散化的做法: 其实这道题是没有必要用线段树的,树状数组就能够解决.但是个人感觉把线段树用熟了会比树状数组更有 ...
- Codeforces Round #677 (Div. 3) E、G题解
E. Two Round Dances #圆排列 题目链接 题意 \(n\)(保证偶数)个人,要表演一个节目,这个节目包含两种圆形舞蹈,而每种圆形舞蹈恰好需要\(n/2\)个人,每个人只能跳一种圆形舞 ...
- Codeforces Round#402(Div.1)掉分记+题解
哎,今天第一次打div1 感觉头脑很不清醒... 看到第一题就蒙了,想了好久,怎么乱dp,倒过来插之类的...突然发现不就是一道sb二分吗.....sb二分看了二十分钟........ 然后第二题看了 ...
- 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 ...
- Codeforces Round #436 (Div. 2) E. Fire(背包+记录路径)
传送门 题意 给出n种物品,抢救第\(i\)种物品花费时间\(t_i\),价值\(p_i\),截止时间\(d_i\) 询问抢救的顺序及物品价值和最大值 分析 按\(d_i\)排序的目的是防止以下情况 ...
随机推荐
- 浮点类型(double与float及其它们的输入输出)
<1>浮点类型 (1)两种类型 double 字长64位(8个字节),有效数字15,范围大概为2.2* 10^-308 ~ 1.79*10^308,0,nan; float字长32位(4个 ...
- Go笔记(3)-3种go语言的键盘输入详解
go语言的键盘输入详解 go语言中有三种输入函数,分别是: fmt.Scanf() 可以按照指定的格式进行输入 fmt.Scanln() 通过指针将值赋值给变量 fmt.Scan() (1)fmt.S ...
- localhost工具:本地代码的远程之路
在日常的开发过程中,本地代码远程调试一直是最理想的开发状态.本文通过介绍京东集团内开发的一个轻量简单的小工具"localhost",从多角度的方案思考,到原理介绍,到最终的方案落地 ...
- 将mysql的输出文本写回mysql
1 准备工作 1.1 环境准备 操作系统:Microsoft Windows 10 专业工作站版 软件版本:Python 3.9.6 第三方包: pip install pandas2.1.0 pip ...
- [ABC233G] Strongest Takahashi
Problem Statement There is a $N \times N$ grid, with blocks on some squares. The grid is described b ...
- 【问题解决】unable to do port forwarding: socat not found
问题复现 前阵子应公司要求做华为云平台的调研,写了一篇文档包含将华为云CCE下载kuberctl配置及使用kubectl转发流量到本地的操作. 今天一早上同事就发来一个错误界面,说是Java远程调试转 ...
- StarBlog - 2023年底更新内容一览
前言 先说一下我对 StarBlog 这个系列的文章的规划吧,在 StarBlog 的 1.x 版本,我会同步更新两个系列的文章 博客前台+接口开发笔记 (即当前已发布的这一系列文章) 博客Vue后台 ...
- SpringBoot-Validation优雅实现参数校验
1.是什么? 它简化了 Java Bean Validation 的集成.Java Bean Validation 通过 JSR 380,也称为 Bean Validation 2.0,是一种标准化的 ...
- 解决 git中用vim编写文件时,无法写进文字字母以及光标无法移到最右边的问题
解决方法:可以切换到英文输入法,然后按'a' 或者 'i' 或者 'o' 或者's' 等.s好像会删掉一个字母.o会使光标移到文末.
- 面试题:Java中的引用类型有哪几种?特点是什么?
Java中引用类型及特点 强 引用: 最普通的引用 Object o = new Object() 软 引用: 垃圾回收器, 内存不够的时候回收 (缓存) 弱 引用: 垃圾回收器看见就会回收 (防止内 ...