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 ...
随机推荐
- ruoyi vue 前后端分离版本 打包分离jar包至lib
环境:若依前后端分离版本,原打包时将所有的依赖jar包放至ruoyi-admin.jar 包中,该包130MB,过大. 需求:为了减少打包更新上传的时间,减少至1.1mb 1.将不常更新的模块jar包 ...
- 使用Slurm集群进行分布式图计算:对Github网络影响力的系统分析
本文分享自华为云社区<基于Slurm集群的分布式图计算应用实践:Github协作网络影响力分析>,作者:yd_263841138 . 1. 引言 Slurm(Simple Linux Ut ...
- QT最小化程序到托盘运行
MinTray 说明 实现程序关闭时最小化托盘的功能 托盘实现显示主页面和退出的功能 支持扩展,直接引用TrayIcon类即可,对外暴露接口 单例实现,可复用 警告 注:博主所有资源永久免费,若有帮助 ...
- Codeforces Round #426 (Div. 2) A. The Useless Toy
A. The Useless Toy time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- 开发AI量化策略所遇到的坑
AI只是工具,想要驾驭AI还得自身有点功底,不然反而会被工具所害,甚至从信仰AI变为抵制AI.本文简单介绍开发AI量化选股策略中所遇到的各种坑,希望大家有所收获,少走弯路. 本文为BigQuant用户 ...
- 测试member和coupon的远程调用
测试member和coupon的远程调用 想要获取当前会员领取到的所有优惠券.先去注册中心找优惠券服务, 注册中心调一台优惠券服务器给会员,会员服务器发送请求给这台优 惠券服务器,然后对方响应. Fe ...
- ElasticSearch之Slow Log
ElasticSearch的慢日志,相关的参数及配置方法. 在log4j2.properties中配置慢日志的输出文件名. Search Slow Log 相关参数 index.search.slow ...
- 【李南江】从零玩转TypeScript
前言 老套路肯定是 需要知道TS是干啥用的啦. 1.什么是TypeScript(TS)? TypeScript简称TS TS和JS之间的关系其实就是Less/Sass和CSS之间的关系 就像Less/ ...
- JavaFx设置图标(二)
JavaFx设置图标(二) JavaFX 从入门入门到入土系列 JavaFx设置图标,需要注意,我这里是Maven管理项目 需要将图片放到resources/img/avatar.jpg下 impor ...
- CSS3学习笔记-盒模型
CSS盒模型是指包含内容(content).填充(padding).边框(border)和外边距(margin)几个方面的一个矩形框模型. 内容区(content):指元素中显示内容的区域,它的大小由 ...