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\)排序的目的是防止以下情况 ...
随机推荐
- SpringBoot接口开发
依赖的jar包<dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...
- HttpClient报错Timeout waiting for connection from pool
报错现象 线上项目使用HttpClient请求第三方的HTTP资源,并发量高的时候,日志框报Timeout waiting for connection from pool 客户端的现象是有时正常,有 ...
- vertx 的http服务表单提交与mysql验证
1.依赖 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http:/ ...
- [ABC266G] Yet Another RGB Sequence
Problem Statement You are given integers $R$, $G$, $B$, and $K$. How many strings $S$ consisting of ...
- skywalking自定义插件开发
skywalking是使用字节码操作技术和AOP概念拦截Java类方法的方式来追踪链路的,由于skywalking已经打包了字节码操作技术和链路追踪的上下文传播,因此只需定义拦截点即可. 这里以sky ...
- 使用ztncui配置私有化zerotier服务器
众所周知,Zerotier-One是一个非常好的组建虚拟局域网的工具,可以以p2p的方式穿透NAT网络进行连接.但是在使用中也仍然存在着一些瑕疵,主要就是以下两点: 因为Zerotier官方提供的中心 ...
- 免费背景音人声分离解决方案MVSEP-MDX23,足以和Spleeter分庭抗礼
在音视频领域,把已经发布的混音歌曲或者音频文件逆向分离一直是世界性的课题.音波混合的物理特性导致在没有原始工程文件的情况下,将其还原和分离是一件很有难度的事情. 言及背景音人声分离技术,就不能不提Sp ...
- JAVAAPI实现血缘关系Rest推送到DataHub V0.12.1版本
DataHub 更青睐于PythonAPI对血缘与元数据操作 虽然开源源码都有Java示例和Python示例:但是这个API示例数量简直是1:100的差距!!不知为何,项目使用Java编写,示例推送偏 ...
- 案例分享-Exception.getMessage突然为null
背景 之前做的小工具一个jsqlparse+git做的小工具帮我节省时间摸鱼昨天突然停止工作,看了下jvm并没有退出,但是看日志确实有不少Error输出,虽说是一个普通的NPE,但是分析了一下却疑点重 ...
- 聊聊ChatGLM-6B的源码分析
基于ChatGLM-6B第一版,要注意还有ChatGLM2-6B以及ChatGLM3-6B 转载请备注出处:https://www.cnblogs.com/zhiyong-ITNote/ Prefix ...