Codeforces Round #715 (Div. 2) (A~D 补题记录)
补题链接:Here
经典手速场
1509A. Average Height
题意:要找出最大不平衡对序列
先输出奇数,然后输出偶数
void solve() {
int n;
cin >> n;
vector<int> odd, even;
for (int i = 0, x; i < n; ++i) {
cin >> x;
if (x & 1) odd.push_back(x);
else
even.push_back(x);
}
for (int x : odd) cout << x << " ";
for (int x : even) cout << x << " ";
cout << "\n";
}
1509B. TMT Document
题意:给定一个 T
-M
字符串,求问是否能全拆分为 TMT
子序列
思路:
要能组成 TMT
就要是 T、M顺序一定并 cntT = 2 * cntM
和 \(n \% 3== 0\)
void solve() {
int n;
string s;
cin >> n >> s;
int ct = 0, cm = 0;
bool f = true;
for (int i = 0; f && i < n; ++i) {
s[i] == 'T' ? ct++ : cm++;
if (cm > ct || (ct > 2 * cm + n / 3 - cm)) f = false;
}
cout << (f && cm * 2 == ct && n % 3 == 0 ? "YES\n" : "NO\n");
}
1509C. The Sports Festival
题意:
学生会要参加接力赛,每位成员跑步速度为 \(a_i\) ,给定定义:
\]
求出最小的 \(\sum_{i = 1}^n d_i\)
思路:
待补。
using ll = long long;
ll dp[2005][2005];
int n;
int A[2005];
void solve() {
cin >> n;
for (int i = 1; i <= n; ++i) cin >> A[i];
sort(A + 1, A + n + 1);
for (int i = 1; i <= n; ++i)
for (int j = i + 1; j <= n; ++j) dp[i][j] = 1e18;
for (int i = 1; i <= n; ++i) dp[i][i] = 0;
for (int len = 1; len < n; ++len) {
for (int i = 1; i + len - 1 <= n; ++i) {
int j = i + len - 1;
if (j < n) dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + A[j + 1] - A[i]);
if (i > 1) dp[i - 1][j] = min(dp[i - 1][j], dp[i][j] + A[j] - A[i - 1]);
}
}
cout << dp[1][n] << '\n';
}
另外一种写法
using ll = long long;
void solve() {
int n;
cin >> n;
vector<ll> s(n);
for (ll &x : s) cin >> x;
sort(s.begin(), s.end());
vector<ll> dp0(n), dp1(n);
for (int k = 1; k < n; ++k) {
for (int i = k; i < n; ++i)
dp1[i] = min(dp0[i - 1], dp0[i]) + s[i] - s[i - k];
swap(dp0, dp1);
}
cout << dp0[n - 1] << '\n';
}
1508A/1509D. Binary Literature
题意:
在一场二进制小说写作比赛中,需要由三个长度为 \(2 · n\) 的字符串组成的 \(3 · n\) 长度的字符串(其中至少包括 \(3\) 个字符串的两个作为子序列)
先贴一下AC代码
void solve() {
int n;
string a, b, c;
cin >> n >> a >> b >> c;
int x = 0, y = 0, z = 0;
for (int i = 0; i < 2 * n; ++i) {
if (a[i] == '1') ++x;
if (b[i] == '1') ++y;
if (c[i] == '1') ++z;
}
if (x > y) swap(a, b), swap(x, y);
if (y > z) swap(b, c), swap(y, z);
if (x > y) swap(a, b), swap(x, y);
char cc = '0';
if (y > n) {
cc = '1';
swap(a, c), swap(x, z);
}
x = y = 0;
string ans = "";
while (true) {
while (x < 2 * n && a[x] != cc) ans += a[x], ++x;
while (y < 2 * n && b[y] != cc) ans += b[y], ++y;
if (x == 2 * n && y == 2 * n) break;
ans += cc;
if (x < 2 * n) x++;
if (y < 2 * n) y++;
}
while (ans.size() < 3 * n) ans += '0';
cout << ans << '\n';
}
Codeforces Round #715 (Div. 2) (A~D 补题记录)的更多相关文章
- Codeforces Round #524 (Div. 2)(前三题题解)
这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...
- Codeforces Round #426 (Div. 2)A B C题+赛后小结
最近比赛有点多,可是好像每场比赛都是被虐,单纯磨砺心态的作用.最近讲的内容也有点多,即便是点到为止很浅显的版块,刷了专题之后的状态还是~"咦,能做,可是并没有把握能A啊".每场网络 ...
- Codeforces Round #243 (Div. 2) B(思维模拟题)
http://codeforces.com/contest/426/problem/B B. Sereja and Mirroring time limit per test 1 second mem ...
- Codeforces Round #340 (Div. 2) B. Chocolate 水题
B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...
- Codeforces Round #340 (Div. 2) A. Elephant 水题
A. Elephant 题目连接: http://www.codeforces.com/contest/617/problem/A Descriptionww.co An elephant decid ...
- Codeforces Round #340 (Div. 2) D. Polyline 水题
D. Polyline 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co There are three p ...
- Codeforces Round #338 (Div. 2) A. Bulbs 水题
A. Bulbs 题目连接: http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...
- Codeforces Round #185 (Div. 2) B. Archer 水题
B. Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/problem/B D ...
- Codeforces Round #282 (Div. 1) A. Treasure 水题
A. Treasure Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/494/problem/A ...
- Codeforces Round #327 (Div. 2) B. Rebranding 水题
B. Rebranding Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/problem ...
随机推荐
- Docker-Compose部署Gitlab以及Gitlab配置SMTP邮件服务
使用Docker-Compose部署Gitlab 拉取镜像 地址: https://hub.docker.com/r/gitlab/gitlab-ce/tags 拉取到镜像后,使用docker tag ...
- js剪贴板应用clipboardData
clipboardData 对象 提供了对剪贴板的访问. 三个方法 1.clearData(sDataFormat) 删除剪贴板中指定格式的数据. 2.getData(sDataFormat) 从剪贴 ...
- [CF1854D] Michael and Hotel
题目描述 Michael and Brian are stuck in a hotel with $ n $ rooms, numbered from $ 1 $ to $ n $ , and nee ...
- C++学习笔记二:变量与数据类型(整型)
1.int(整型数据): 1.1 进制的表示:十进制,八进制,16进制,二进制 int number1 = 15; // Decimal int number2 = 017; // Octal int ...
- 华企盾DSC客户端右键菜单不显示常见处理方法
1.检查控制台"客户端不显示右键菜单项" 2.未分发模块权限,若以分配可尝试去掉重新分配模块 3.检查杀毒软件是否杀掉了5097目录的文件(覆盖安装,以上两条没问题,这条比较常见) ...
- python tkinter使用(四)
python tkinter使用(四) 本篇文章主要讲下tkinter 的文本框相关. tkinter中用Entry来实现输入框,类似于android中的edittext. 具体的用法如下: 1:空白 ...
- C#与数据库访问技术之ExecuteNonQuery方法
ExecuteNonQuery方法主要用来更新数据. 通常使用它来执行Update.Insert和Delete语句. 该方法返回值意义如下: 对于Update.Insert和Delete语句,返回值为 ...
- Python——第三章:内置函数(上)
Python中的内置函数 基础数据类型相关(38) 和数字相关(14) 数字类型(4) bool--布尔型 int--整型 float--浮点型 complex--虚数 机制转换(3) bin--二进 ...
- 未能加载文件或程序集“*****.dll”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。(异常来自HRESULT:0x80131040)
问题描述: 未能加载文件或程序集"*****.dll"或它的某一个依赖项.找到的程序集清单定义与程序集引用不匹配.(异常来自HRESULT:0x80131040) 解决方法: 1. ...
- CUDA驱动深度学习发展 - 技术全解与实战
全面介绍CUDA与pytorch cuda实战 关注TechLead,分享AI全维度知识.作者拥有10+年互联网服务架构.AI产品研发经验.团队管理经验,同济本复旦硕,复旦机器人智能实验室成员,阿里云 ...