Codeforces Round #619 (Div. 2) A-D
比赛链接:Here
1301A. Three Strings
题意:
给三个相同长的字符串 \(a,b,c\) ,对于每个位置 \(i\) ,你必须做一次操作:交换 \(a_i\) 和 \(c_i\) ,或者交换 \(b_i\) 和 \(c_i\)。问你交换完之后 \(a\) 和 \(b\) 能否一样。
因为每个位置必须交换,所以每个位置只要 \(a_i = c_i\) 或者 \(b_i = c_i\) 即可
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
string a, b, c;
cin >> a >> b >> c;
bool f = 1;
for (int i = 0; f and i < a.size(); ++i) {
if (a[i] == c[i] || b[i] == c[i]) continue;
f = 0;
}
cout << (f ? "YES\n" : "NO\n");
}
}
1301B. Motarack's Birthday
题意:
给一个长为 \(n\) 的整数数组,其中有一些数消失了,用 \(-1\) 代替,其他数大于等于 \(0\),然后叫你找一个非负数 \(k\) ,使得用 \(k\) 替代所有 \(-1\) 后,相邻元素的差值的最大值,这个值要最小。
思路:
差值最大值无非就是,原来就有的数之间的相邻差值最大值,和替换后k与原来就有的数的差值的最大值里求一个 \(\max\) 。前者可以直接求的,后者当 \(k\) 取到 \((m_i+mx)/2\) 时取到最小。\(m_i\) 为与 \(k-1\) 邻的原来有的数的最小值,\(mx\) 为最大值。
const int N = 1e5 + 10;
ll a[N];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
int n; cin >> n;
for (int i = 0; i < n; ++i) cin >> a[i];
ll base = 0;
vector<ll>v;
for (int i = 0; i < n - 1; ++i) {
if (a[i] == -1 and a[i + 1] != -1) v.push_back(a[i + 1]);
else if (a[i] != -1 and a[i + 1] == -1) v.push_back(a[i]);
else if (a[i] != -1 and a[i] != -1) base = max(base, abs(a[i] - a[i + 1]));
}
if (v.empty()) {cout << "0 0\n"; continue;}
sort(v.begin(), v.end());
int k = (v.back() + *v.begin()) / 2;
cout << max(max(v.back() - k, k - v[0]), base) << " " << k << "\n";
}
}
1301C. Ayoub's function
题意:
函数 \(f(s)\) 代表,\(01\) 字符串 \(s\) 中包含至少一个 \(1\) 的子串的数量。问你所有长度为 \(n\) ,其中有 \(m\) 个 \(1\) 的 \(01\) 字符串中。使得 \(f(s)\) 的值最大为多少。
做法:
至少包含一个 \(1\) 的子串的数量 \(=\) 所有子串的数量 \(-\) 只包含\(0\) 的子串的数量。
所以要使得 \(f(s)\) 越大,只包含 \(0\) 的子串的数量要越小越好,于是 \(01\) 字符串中每一段的连续的 \(0\) 的个数应尽可能一样。\(m\) 个 \(1\) ,有 \(n-m\) 个 \(0\) ,被分成 \(m+1\) 段,长度为 \((n-m)/(m+1)+1\) 的连续 \(0\) 的段数为 \((n-m)%(m+1)\) ,长度为 \((n-m)/(m+1)\) 的连续 \(0\) 的段数为 \(m+1-(n-m)%(m+1)\) 。再计算一下可得答案。
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
ll n, m; cin >> n >> m;
ll ans = n * (n + 1) / 2;
ll num = (n - m) / (m + 1);
ll r = (n - m) % (m + 1);
cout << (ans - r * (num + 1) * (num + 2) / 2 - (m + 1 - r) * num * (num + 1) / 2) << "\n";
}
}
1301D. Time to Run
题意:
\(n*m\) 的网格,相邻网格间有两条道路(不同方向)。问你能否不重复的走 \(k\) 条路,可以的话输出路径。按题目要求。

思路:
真就直接走完咯,先左右走,到最后一行只往右,到右下角之后上下走,ok,然后题目要求 \(k\) ,边走边减,到 \(0\) 为止即可。 如果全部都走过了 \(k\) 还有剩就输出 NO.
int n, m, k;
vector<pair<int, string>>v, ans;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> m >> k;
for (int i = 0; i < n - 1; ++i) {
if (m != 1) {
v.push_back({m - 1, "R"});
v.push_back({m - 1, "L"});
}
v.push_back({1, "D"});
}
if (m != 1) v.push_back({m - 1, "R"});
for (int i = 0; i < m - 1; ++i) {
if (n != 1) {
v.push_back({n - 1, "U"});
v.push_back({n - 1, "D"});
}
v.push_back({1, "L"});
}
if (n != 1) v.push_back({n - 1, "U"});
for (int i = 0; i < v.size(); ++i) {
if (k >= v[i].first) {
k -= v[i].first;
ans.push_back(v[i]);
} else if (k != 0) {
ans.push_back({k, v[i].second});
k = 0;
}
}
if (k > 0) cout << "NO\n";
else {
cout << "YES\n";
cout << ans.size() << "\n";
for (auto p : ans) cout << p.first << " " << p.second << "\n";
}
}
Codeforces Round #619 (Div. 2) A-D的更多相关文章
- Codeforces Round #619 (Div. 2)E思维+二维RMQ
题:https://codeforces.com/contest/1301/problem/E 题意:给个n*m的图形,q个询问,每次询问问询问区间最大的合法logo的面积是多少 分析:由于logo是 ...
- Codeforces Round #619 (Div. 2) A~D题解
最近网课也开始了,牛客上一堆比赛题目也没补,所以就D题后面的也懒得补了 A.Three String 水题 #include <cstdio> #include <cstring&g ...
- Codeforces Round #619 (Div. 2)D(模拟)
先把一种最长路线记录下来,根据k的大小存到ans中相应的答案再输出 #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using n ...
- Codeforces Round #619 (Div. 2)C(构造,容斥)
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; int main(){ ios::syn ...
- Codeforces Round #619 (Div. 2) Ayoub's function
Ayoub thinks that he is a very smart person, so he created a function f(s)f(s) , where ss is a binar ...
- Codeforces Round #619 (Div. 2) B. Motarack's Birthday
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motar ...
- Codeforces Round #619 (Div. 2) A. Three Strings
You are given three strings aa , bb and cc of the same length nn . The strings consist of lowercase ...
- Codeforces Round #619 (Div. 2)
A. Three Strings 题意:给三个长度相同的非空字符串abc,依次将c中的每个字符和a或者b中对应位置的字符进行交换,交换必须进行,问能否使得ab相同. 思路:对于每一个位置,如果三个字符 ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
随机推荐
- Kotlin协程系列(一)
一.协程的定义 最近看了一本有关kotlin协程的书籍,对协程又有了不一样的了解,所以准备写一个关于kotlin协程系列的文章. 言归正传,我们在学习一个新东西的时候,如果连这个东西"是什么 ...
- timeSetEvent()函数定时器的使用
1.定时器函数的使用 微软公司在其多媒体Windows中提供了精确定时器的底层API支持,利用多媒体定时器可以很精确地读出系统的当前时间,并且能在非常精确的时间间隔内完成一个事件.函数或过程的调用. ...
- Bash—source命令&export命令&bashrc文件
当不使用 source 命令执行脚本时,会创建一个子 shell,在该子 shell 中执行完脚本后退出子 shell.不是用 export 定义的变量只对该 shell 有效,对子 shell 是无 ...
- 离散傅里叶变换DFT的应用
目录 一维DFT 1 DFT的相关内容 2 DFT计算结果验证 3 DFT的时频曲线分析 4 DFT的应用 二维DFT 1 DFT在图像处理时的相关内容 2 DFT滤波应用 一维DFT 1 DFT的相 ...
- 【源码系列#03】Vue3计算属性原理(Computed)
专栏分享:vue2源码专栏,vue3源码专栏,vue router源码专栏,玩具项目专栏,硬核推荐 欢迎各位ITer关注点赞收藏 语法 传入一个 getter 函数,返回一个默认不可手动修改的 ref ...
- ubuntu安装opencv的正确方法
本文介绍的是如何安装ubuntu下C++接口的opencv 1.安装准备: 1.1安装cmake sudo apt-get install cmake 1.2依赖环境 sudo apt-get ins ...
- 华企盾DSC客户端连不上服务器(客户端在回收站)
解决方法:确保该计算机在CLIENT表recyclebin列中的值为False,最好把所有计算机都改成False,改好后重启DSC服务器,最后重新安装客户端. 或者将客户端从回收站移动到正常的工作组.
- npm 发布流程
登录npm 查看本地是否登录 # 全局配置源 npm who am i # 官方源 npm who am i --registry https://registry.npmjs.org 注: npm源 ...
- MinIO客户端之license
MinIO提供了一个命令行程序mc用于协助用户完成日常的维护.管理类工作. 官方资料 mc license mc license info mc license register mc license ...
- Codeforce Round 916(div3)
Codeforces Round 916(div3) [Problem - A - Codeforces]:Problemsolving Log A.题 直接看样例进行分析,发现每一次出现的字符代表着 ...