Educational Codeforces Round 97 (Rated for Div. 2) (A - D题个人题解)
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题个人题解)的更多相关文章
- Educational Codeforces Round 97 (Rated for Div. 2)
补了一场Edu round. A : Marketing Scheme 水题 #include <cstdio> #include <algorithm> typedef lo ...
- Educational Codeforces Round 97 (Rated for Div. 2) E. Make It Increasing(最长非下降子序列)
题目链接:https://codeforces.com/contest/1437/problem/E 题意 给出一个大小为 \(n\) 的数组 \(a\) 和一个下标数组 \(b\),每次操作可以选择 ...
- Educational Codeforces Round 97 (Rated for Div. 2)【ABCD】
比赛链接:https://codeforces.com/contest/1437 A. Marketing Scheme 题解 令 \(l = \frac{a}{2}\),那么如果 \(r < ...
- Educational Codeforces Round 97 (Rated for Div. 2) D. Minimal Height Tree (贪心)
题意:有一个从根节点\(BFS\)得来的序列(每次\(bfs\)子节点的时候保证是升序放入队列的),现在让你还原树(没必要和之前相同),问能构造出的最小的树的深度. 题解:不看根节点,我们从第二个位置 ...
- Educational Codeforces Round 97 (Rated for Div. 2) C. Chef Monocarp (DP)
题意:有\(n\)个菜在烤箱中,每个时刻只能将一个菜从烤箱中拿出来,第\(i\)个时刻拿出来的贡献是\(|i-a[i]|\),你可以在任意时刻把菜拿出来,问将所有菜拿出的最小贡献是多少? 题解: 先对 ...
- Educational Codeforces Round 59 (Rated for Div. 2) (前四题)
A. Digits Sequence Dividing(英文速读) 练习英语速读的题,我还上来昏迷一次....只要长度大于2那么一定可以等于2那么前面大于后面就行其他no 大于2的时候分成前面1个剩下 ...
- 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 ...
- 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 ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
随机推荐
- 神经网络入门篇:详解搭建神经网络块(Building blocks of deep neural networks)
搭建神经网络块 这是一个层数较少的神经网络,选择其中一层(方框部分),从这一层的计算着手.在第\(l\)层有参数\(W^{[l]}\)和\(b^{[l]}\),正向传播里有输入的激活函数,输入是前一层 ...
- SpringBoot获取启动类Application所在包路径
1. @SpringBootApplication 注解中引用了@EnableAutoConfiguration 注解. 2.查看 @EnableAutoConfiguration 注解,发现引用了 ...
- [NOI online2022普及B] 数学游戏
题目描述 Kri 喜欢玩数字游戏. 一天,他在草稿纸上写下了 \(t\) 对正整数 \((x,y)\),并对于每一对正整数计算出了 \(z=x\times y\times\gcd(x,y)\). 可是 ...
- 项目实战接口开发SpringBoot
目录 一.springboot官方demo开发 二.使用SpringBoot开发get方法接口 三.一个要求携带cookie信息访问的get接口开发 四.需要携带参数的get请求两种开发方式 4.1 ...
- storeToRefs()的作用和使用
store 是一个用 reactive 包装的对象,这意味着不需要在 getters 后面写 .value,就像 setup 中的 props 一样,如果你写了,我们也不能解构它: <scrip ...
- MyBatisPlus配置类-配置分页插件,注册为bean对象
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; import org.mybatis.spring.a ...
- linux文件摘选
显示/var目录下所有以1开头,以一个小写字母结尾,且中间至少出现一位数字(可以由其他字符)的文件或目录. 命令: ls -d /var/1*[0-9]*[a-z] [root@foundation0 ...
- P9344 去年天气旧亭台 代码
不带滚动数组代码: #include <iostream> #include <cstdio> #include <cstring> #define int lon ...
- 笔记本为什么不出可升级CPU的,用台式CPU不行吗?
我十几年年前的thinkpad 通过更换cpu复活了:联想ThinkPad E430c i3变i7:笔记本电脑CPU升级思路-CPU参数 为什么现在的市面上可以更换cpu的笔记本非常稀少呢? inte ...
- ubuntu 之 lftp 上传 和下载
1. 安装 sudo apt-get install lftp 2. 简单教程 2.0 声明:上传或下载文件 用get 或 mget,这种方式 不包含文件夹本身,如果需要连文件夹一起上传或下载则需要使 ...