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 ...
随机推荐
- Django的staticfiles库
staticfiles 库是 Django 提供的一个用于管理静态文件的库,它提供了一些工具和函数来帮助开发者在 Django 应用程序中管理和提供静态文件服务. 在 Django 应用程序中,静态文 ...
- 使用nacos配置无效,原因:项目中 gateway服务配置的 application的name:@artifactId@ 和nacos上配置的DataID 不一致导致
遇到一个问题,项目启动后一致无法正常登陆进入后端,登陆时一直报错返回null,排查后发现是自己粗心,项目中 gateway服务配置的 application的name:@artifactId@ 和 ...
- [ARC165E] Random Isolation
Problem Statement There is a tree with $N$ vertices numbered $1$ to $N$. The $i$-th edge connects ve ...
- JDK8提供的常用计量单位
时间计量单位:Duration @DurationUnit(ChronoUnit.HOURS) private Duration serverTimeout; 空间计量单位:DataSize @Dat ...
- SpringBoot设置日志级别
输出到控制台 logging: # 日志记录到文件中 file: # 指定文件名 name: server.log logback: rollingpolicy: # 指定文件大小 max-file- ...
- Linux查看内存使用情况以及释放内存
查看内存使用情况 一般使用 top 命令即可,命令行输入 top会实时显示内存和cpu等硬件的使用情况,然后输入M即显示内存的使用情况. 但是有些情况下,内存明明被占用了,但是使用top命令依然无法找 ...
- Java并发(二十)----synchronized原理进阶
1.小故事 故事角色 老王 - JVM 小南 - 线程 小女 - 线程 房间 - 对象 房间门上 - 防盗锁 - Monitor-重量级锁 房间门上 - 小南书包 - 轻量级锁 房间门上 - 刻上小南 ...
- Critical error detected c0000374
我发现出现上述错误是 free 两次内存 float* dd=new float[2]; delete[] dd; delete[] dd;
- Cisco 交换机利用CDP数据自动绘制网络拓扑图[drawio]-实践
进行网络运维,必须对网络拓扑情况进行详细的掌握,但是网络改动后,更新网络拓扑比较繁琐,维护人员容易懈怠,久而久之,通过人工绘制的网络拓扑很容易与现有网络出现偏差. 现在,可以通过python 丰富的库 ...
- 【源码系列#04】Vue3侦听器原理(Watch)
专栏分享:vue2源码专栏,vue3源码专栏,vue router源码专栏,玩具项目专栏,硬核推荐 欢迎各位ITer关注点赞收藏 语法 侦听一个或多个响应式数据源,并在数据源变化时调用所给的回调函数 ...