补题链接: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\) ,给定定义:

\[d_i = max(a_1,a_2,\dots,a_i) - min(a_1,a_2,\dots,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 补题记录)的更多相关文章

  1. Codeforces Round #524 (Div. 2)(前三题题解)

    这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...

  2. Codeforces Round #426 (Div. 2)A B C题+赛后小结

    最近比赛有点多,可是好像每场比赛都是被虐,单纯磨砺心态的作用.最近讲的内容也有点多,即便是点到为止很浅显的版块,刷了专题之后的状态还是~"咦,能做,可是并没有把握能A啊".每场网络 ...

  3. Codeforces Round #243 (Div. 2) B(思维模拟题)

    http://codeforces.com/contest/426/problem/B B. Sereja and Mirroring time limit per test 1 second mem ...

  4. Codeforces Round #340 (Div. 2) B. Chocolate 水题

    B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...

  5. Codeforces Round #340 (Div. 2) A. Elephant 水题

    A. Elephant 题目连接: http://www.codeforces.com/contest/617/problem/A Descriptionww.co An elephant decid ...

  6. Codeforces Round #340 (Div. 2) D. Polyline 水题

    D. Polyline 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co There are three p ...

  7. Codeforces Round #338 (Div. 2) A. Bulbs 水题

    A. Bulbs 题目连接: http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...

  8. 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 ...

  9. Codeforces Round #282 (Div. 1) A. Treasure 水题

    A. Treasure Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/494/problem/A ...

  10. Codeforces Round #327 (Div. 2) B. Rebranding 水题

    B. Rebranding Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/problem ...

随机推荐

  1. C# 基础编程题集锦

    简单字符串加密 编写一个应用程序用来输入的字符串进行加密,对于字母字符串加密规则如下: 'a→d' 'b'→'e' 'w'→z' ...... x'→'a' 'y'→b' 'z→c' 'A'→'D' ...

  2. SpringBoot整合阿里云OSS

    1.创建一个service_ossspringboot项目 2.导入相关依赖 ...其他的依赖大家自行导入 <!-- 阿里云oss依赖 --> <dependency> < ...

  3. LeetCode54、59:螺旋矩阵|、||(递归,模拟)

    解题思路:定义一个方向数组,用栈或者直接从左上角的起点进行DFS,如果碰到下一步无法访问,调整方向,继续遍历,直到所有元素都访问了. (这道题好有历史感,到现在还记得我读大一的时候参加院队培训的时候做 ...

  4. 如何在LinkedIn上开发客户

    LinkedIn作为一个职场社交平台,提供了许多开发外贸客户的机会和工具.通过在LinkedIn上建立个人和公司的专业形象.分享有价值的内容.参与行业社群和利用广告推广,您可以扩大您的业务网络,找到更 ...

  5. ElasticSearch之线程的数量

    ElasticSearch在运行过程中,涉及多种线程池.线程的使用,因此而需要给予足够的线程资源,保证ElasticSearch在需要时可以正常创建出线程. 查看Linux系统当前用户允许创建的线程的 ...

  6. 春秋云镜 - CVE-2022-29464

    WSO2文件上传漏洞(CVE-2022-29464)是Orange Tsai发现的WSO2上的严重漏洞.该漏洞是一种未经身份验证的无限制任意文件上传,允许未经身份验证的攻击者通过上传恶意JSP文件在W ...

  7. 部署堡垒机5——安装Core

    部署jumpserver服务核心组件Core 一.前期准备 一个后台程序,基本上都是需要依赖于数据库才能运行,后台程序在启动的时候,代码就回去连接数据库,保证数据库,正确启动,且可以正确连接,否则后台 ...

  8. gsamplerCubeArrayShadow isn't supported in textureGrad, textureLod or texture with bias

    问题描述 跑rust的Bevy示例程序 运行3d的示例,cargo run --example 3d_shapes 发现报错: INFO bevy_render::renderer: AdapterI ...

  9. java生成企业公章图片源代码

    企业公章图片在电子签章业务中应用广泛,在电子签章应用过程中首先需要生成公章图片,然后再使用公章图片结合数字签名技术完成电子签,这样就实现了从可视化到不可篡改的数字化电子签章功能,以下是企业公章图片生成 ...

  10. B 树和 B+ 树及其实现

    B 树 B 树和一般的二叉树有许多相似的地方,二者都是为了加快查找的速度,不同之处在于 B 树是为了解决大量的数据而产生的,更加适合读取相对大的数据块的存储系统.B 树的每个节点一般不会存储实际的数据 ...