Educational Codeforces Round 130 (Rated for Div. 2) A--C
Educational Codeforces Round 130 (Rated for Div. 2)
A. Parkway Walk
题目描述
求走完所有距离所需最小的补充能量数
题目分析
用所需总能量数减去初始能量即可
code
#include<bits/stdc++.h>using namespace std;int n, m, k, t;void solve()
{int sum = 0;cin >> n >> m;for(int i = 0; i < n; i ++){int u;cin >> u;sum += u;}if(sum <= m)puts("0");else cout << sum - m << "\n";
}int main()
{cin >> t;while(t --) solve();return 0;
}
B. Promo
题目描述
如果顾客购买了至少 x 件商品,最便宜的y件商品都是免费的。对于每次询问求各科可以免费获得商品的最大价值
题目分析
用贪心的思维则我们尽可能选择大的,这样能使得其中y个较小的值最大化。对于所免费获得的价值,我们可以用前缀和来计算,从而达到降低时间复杂度的目的
code
#include<bits/stdc++.h>using namespace std;const int N = 2e5 + 10;
typedef long long ll;int n, m, k, t;
ll a[N], s[N];bool cmp(int a, int b)
{return a > b;
}int main()
{cin >> n >> t;for(int i = 1; i <= n; i ++)cin >> a[i];sort(a + 1, a + n + 1, cmp);for(int i = 1; i <= n; i ++){s[i] = s[i - 1] + a[i];//cout << s[i] << "---\n";}while(t --){int x, y;cin >> x >> y;cout << s[x] - s[x-y] << "\n";}return 0;
}
C. awoo’s Favorite Problem
题目描述
问字符串a能否通过两种操作变成b: 操作1(将 ab 变成 ba) 操作2(将 bc 变成 cb)
题目分析
两个操作的共性都是通过b
来改变字母的相对位置,我们首先可以去掉两个字符串当中的b
,若得到的字符串不相等则一定无法完成变换
此外根据观察可以发现,a的位置只能向后移动,c的位置只能向前。所以在字符串a中的字符a
位置一定小于等于在字符串b 中的,字符c
的情况相反
通过以上两部分判断即可
code
#include<bits/stdc++.h>using namespace std;const int N = 1e5 + 10;int n, m, k, t;void solve()
{int a[N] = {0}, b[N] = {0}, a1[N] = {0}, b1[N] = {0};int co1 = 0, co2 = 0, co3 = 0, co4 = 0;string s, r, s1, r1;s1.clear(), r1.clear();cin >> n >> s >> r;for(int i = 0; i < n; i ++){if(s[i] != 'b') s1 += s[i];if(s[i] == 'a') a[co1 ++] = i;if(s[i] == 'c') b[co2 ++] = i;if(r[i] != 'b') r1 += r[i];if(r[i] == 'a') a1[co3 ++] = i;if(r[i] == 'c') b1[co4 ++] = i;}//cout << s1 << "--" << r1 << "\n";if(s1 != r1) puts("NO");else{for(int i = 0; i < co1; i ++){if(a[i] > a1[i]){puts("NO");return;}}for(int i = 0; i < co2; i ++){if(b[i] < b1[i]){puts("NO");return;}}puts("YES");}
}int main()
{cin >> t;while(t --) solve();return 0;
}
Educational Codeforces Round 130 (Rated for Div. 2) A--C相关推荐
- Educational Codeforces Round 114 (Rated for Div. 2) (A ~ F)全题解
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Educational Codeforces Round 114 (Rated for Div. 2) ...
- Educational Codeforces Round 106 (Rated for Div. 2)(A ~ E)题解(每日训练 Day.16 )
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 Educational Codeforces Round 106 (Rated for Div. ...
- Educational Codeforces Round 37 (Rated for Div. 2) 1
Educational Codeforces Round 37 (Rated for Div. 2) A.Water The Garden 题意:Max想给花园浇水.花园可被视为长度为n的花园床,花园 ...
- Educational Codeforces Round 90 (Rated for Div. 2)(A, B, C, D, E)
Educational Codeforces Round 90 (Rated for Div. 2) Donut Shops 思路 分三种情况: a==c/ba == c / ba==c/b这个时候两 ...
- Educational Codeforces Round 89 (Rated for Div. 2)(A, B, C, D)
Educational Codeforces Round 89 (Rated for Div. 2) A. Shovels and Swords 思路 题意非常简单,就是得到最多的物品嘛,我们假定a, ...
- Educational Codeforces Round 114 (Rated for Div. 2) D. The Strongest Build 暴力 + bfs
传送门 文章目录 题意: 思路: 题意: 你有nnn个装备槽,每个槽里面有cic_ici个力量加成,对于每个槽只能选一个力量加成,现在给你mmm个力量组合[b1,b2,...,bn][b_1,b_2 ...
- Educational Codeforces Round 72 (Rated for Div. 2) D. Coloring Edges dfs树/拓扑找环
传送门 文章目录 题意: 思路: 题意: 给你一张图,你需要给这个图的边染色,保证如果有环那么这个环内边的颜色不全相同,输出染色方案和用的颜色个数. n,m≤5e3n,m\le5e3n,m≤5e3 思 ...
- Educational Codeforces Round 111 (Rated for Div. 2) D. Excellent Arrays 组合数学
传送门 文章目录 题意: 思路: 题意: 给你一个数组aia_iai,定义一个数组是好的当且仅当对于所有iii都有ai!=ia_i!=iai!=i.定义f(a)f(a)f(a)表示数组aaa中i& ...
- Educational Codeforces Round 111 (Rated for Div. 2) E. Stringforces 二分 + 状压dp
传送门 文章目录 题意: 思路: 题意: 给你一个串,只包含前kkk个字母和???,定义fif_ifi表示第iii个字母在串中出现的最长连续长度,你现在需要将???替换为前kkk个字母,使得mini ...
最新文章
- 简单三步-实现dede站内搜索功能
- 【教程】利用libsvm-mat建立分类模型model参数解密【by faruto】
- fpga硬件驱动TFT液晶屏-小结
- 下列不属于计算机图形学的应用的是,《数字图形设计》题目与答案3
- 凯尔卡C68全球版汽车电脑诊断仪
- json 处理日期格式
- Winform使用FTP实现自动更新
- 查看Tomcat版本
- Java 强制删除文件或目录
- LaiCode 376. Ascending Triple I
- 计算机管理员的用户名市什么意思,电脑中的Administrator是什么意思?
- 在mybatis中怎么书写工具类,也就是创建一个sqlsessionFactory
- hexo入门学习(六):文章图片存储到七牛云
- How to craw the Info of BiliBIli with python
- 服务器主控芯片,物联网主控芯片6大架构分析 谁能独当一面
- 十二章 Python入门系列之字典
- 父页面调用子页面方法, 子页面加载父页面传送的数据
- 数说“德尔塔”病毒,数据分析展示变异新冠毒株的传播情况
- 某大型合资企业审批系统上线经验教训总结
- 《算法4》读书笔记(二)