1437A. Marketing Scheme

题意:最近猫粮店正在打折销售猫粮罐头,在给定客人能买的罐头数量区间内求合适包装大小

思路:说实话,在比赛刚开始没看懂题,最后放弃读题直接研究给出的样例解释发现,我们可以假设 \(a = r + 1\) 再进行比较 \(l \% a >= \frac{(a + 1)} 2\)

void solve() {
ll l, r;
cin >> l >> r;
ll a = r + 1;
if (l % a >= (a + 1) / 2) cout << "YES\n";
else cout << "NO\n";
}

1437B. Reverse Binary Strings

题意:给定一个偶数长度的01字符串,求如何在最少的区间反转使得 字符串变为 “101010..."样式

思路:想清楚我们需要得到的是 10"串,那么对于其他情况都是不合法的 ”11,00“对于这些我们进行统计,最后只需要 \(k / 2\)即可

这个思路是比赛过程中观察而来的,证明待补。。。

void solve() {
cin >> n >> s, k = 0;
s[n] = s[0];
for (int i = 0; i < n; ++i)
if (s[i] == s[i + 1]) k++;
cout << k / 2 << endl;
}

1437C. Chef Monocarp

题意:我们有一位高级厨师,他知道每一道菜的美味时间 \(t_i\),但他每一分钟只能端出一道菜(已经拿出来的不能放回),如果拿出则会产生一个不愉快值 \(|T - t_i|\) ,求问怎么取出所有的菜的同时使总的不愉快值最小

思路:经典动态规划问题(脑抽写错了),这道题建议直接看代码理解。

// Author : RioTian
// Time : 20/10/28
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int N = 210;
int dp[N][N << 1], n, _;
void solve() {
cin >> n;
int a[n + 1];
for (int i = 1; i <= n; ++i) cin >> a[i];
sort(a + 1, a + 1 + n);
//模拟时间变化
for (int j = 1; j <= n; ++j)
for (int i = j; i <= 2 * n; ++i) {
int c = 1e6;
for (int k = j; k <= i; ++k) //求出每道菜最小的不愉快值
c = min(c, abs(k - a[j]) + dp[j - 1][k - 1]);
dp[j][i] = c;
}
cout << dp[n][n << 1] << endl;
}
int main() {
// freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> _;
while (_--) solve();
}

1437D. Minimal Height Tree

题意:Monocarp原本有一颗树,但他为了研究BFS将树变成了一组点序列。求问还原这颗树时能构成的最小高度

思路:目前我们已知BFS的入队序列,这样我们可以构建一个二叉树,这样一定能构成一个最短高度的树。

如果有不了解二叉树的同学可以点击这里:Here

以及二叉树常用操作总结:Here

void solve() {
cin >> n;
vector<int> a(n), b(n);
for (auto &it : a) cin >> it;
int l = 0;
b[1] = 0;
for (int i = 1; i < n; ++i) {
if (a[i] < a[i - 1]) l++;
b[i] = b[l] + 1;
}
cout << b[n - 1] << endl;
}

Educational Codeforces Round 97 (Rated for Div. 2) (A - D题个人题解)的更多相关文章

  1. Educational Codeforces Round 97 (Rated for Div. 2)

    补了一场Edu round. A : Marketing Scheme 水题 #include <cstdio> #include <algorithm> typedef lo ...

  2. Educational Codeforces Round 97 (Rated for Div. 2) E. Make It Increasing(最长非下降子序列)

    题目链接:https://codeforces.com/contest/1437/problem/E 题意 给出一个大小为 \(n\) 的数组 \(a\) 和一个下标数组 \(b\),每次操作可以选择 ...

  3. Educational Codeforces Round 97 (Rated for Div. 2)【ABCD】

    比赛链接:https://codeforces.com/contest/1437 A. Marketing Scheme 题解 令 \(l = \frac{a}{2}\),那么如果 \(r < ...

  4. Educational Codeforces Round 97 (Rated for Div. 2) D. Minimal Height Tree (贪心)

    题意:有一个从根节点\(BFS\)得来的序列(每次\(bfs\)子节点的时候保证是升序放入队列的),现在让你还原树(没必要和之前相同),问能构造出的最小的树的深度. 题解:不看根节点,我们从第二个位置 ...

  5. Educational Codeforces Round 97 (Rated for Div. 2) C. Chef Monocarp (DP)

    题意:有\(n\)个菜在烤箱中,每个时刻只能将一个菜从烤箱中拿出来,第\(i\)个时刻拿出来的贡献是\(|i-a[i]|\),你可以在任意时刻把菜拿出来,问将所有菜拿出的最小贡献是多少? 题解: 先对 ...

  6. Educational Codeforces Round 59 (Rated for Div. 2) (前四题)

    A. Digits Sequence Dividing(英文速读) 练习英语速读的题,我还上来昏迷一次....只要长度大于2那么一定可以等于2那么前面大于后面就行其他no 大于2的时候分成前面1个剩下 ...

  7. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  8. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  9. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  10. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

随机推荐

  1. 【结对作业】第一周 | 学习体会day01

    周一老师布置了小组结对作业,内容如下: 我们今天实现了数据库的建立,页面的设计,以及前后端查询的操作,具体实现如下

  2. [ABC246Ex] 01? Queries

    Problem Statement You are given a string $S$ of length $N$ consisting of 0, 1, and ?. You are also g ...

  3. .NET周刊【12月第1期 2023-12-06】

    国内文章 .NET 与 OpenEuler 共展翅,昇腾九万里 https://www.cnblogs.com/shanyou/p/17858385.html 本文介绍了openEuler操作系统,它 ...

  4. 华为防火墙1day?

    背景信息 缺省情况下,FW通过8887端口提供内置的本地Portal认证页面,用户可以主动访问或HTTP重定向至认证页面(https://接口IP地址:8887)进行本地Portal认证. 当企业部署 ...

  5. 手动安装pinia、给项目添加pinia实例

    用你喜欢的js包管理器安装pinia: yarn add pinia # 或者使用 npm npm install pinia 创建一个 pinia 实例 (根 store) 并将其传递给应用: 编辑 ...

  6. 断言可Cookie管理器

    断言可以判断预期结果和实际结果是否一致 可以辅助判断脚本的运行结果是否正确 cookie管理器 记录用户的cookie信息 可以自动记录cookie,也可以使用用户自定义的cookie

  7. 网安区过年-Log4j2

    Log4j2-2021 漏洞原理 Apache Log4j 2 是Java语言的日志处理套件,使用极为广泛.在其2.0到2.14.1版本中存在一处JNDI注入漏洞,攻击者在可以控制日志内容的情况下,通 ...

  8. manjaro下使用deepin-wine5解决wechat无法发送图片的问题

    问题 在manjaro操作系统下,使用了deepin-wine安装wechat.但是,wechat运行无法发送较大图片且截图功能也有问题. 解决 在参考了github之后,我找到了解决方案. 附上链接 ...

  9. 容器处于`Pending`状态Warning FailedScheduling <unknown> default-scheduler 0/10 nodes are available

    Warning FailedScheduling default-scheduler 0/10 nodes are available: 1 node(s) had taint {agreeml: a ...

  10. GetView介绍 以及 GetxController生命周期

    etView 只是对已注册的 Controller 有一个名为 controller 的getter的 const Stateless 的 Widget,如果我们只有单个控制器作为依赖项,那我们就可以 ...