Codeforces Round #493 (Div. 2) C. Convert to Ones 乱搞_构造_好题
每次肯定是对一段连续的 $0$ 或者 $1$ 进行操作.
对于一段连续的 $0$,要么直接变为 $1$,要么与右面的连续的 $1$ 交换.
如果与右面的 $1$ 翻转更加合适,那么就肯定会一直翻转,并在不能交换的时候变为 0.
否则,就会一直将子序列变为 $0$.
即 $ans=min(num[0]\times y,(num[0]-1)\times x+y)$
#include <cstdio>
#include <algorithm>
#define ll long long
#define setIO(s) freopen(s".in", "r" , stdin)
using namespace std;
ll x, y;
char str[300005];
int n ,a[2], i, pre = -1;
int main()
{
// setIO("input");
scanf("%d%lld%lld%s", &n, &x, &y, str + 1);
for(i = 1; i <= n ; ++ i)
{
int cur = str[i] - '0';
scanf("%d", &cur);
if(cur != pre) ++ a[cur], pre = cur;
}
printf("%lld\n", max(1ll*0, min(1ll * a[0] * y, 1ll * (a[0] - 1) * x + y)));
return 0;
}
Codeforces Round #493 (Div. 2) C. Convert to Ones 乱搞_构造_好题的更多相关文章
- Codeforces Round #493 (Div 2) (A~E)
目录 Codeforces 998 A.Balloons B.Cutting C.Convert to Ones D.Roman Digits E.Sky Full of Stars(容斥 计数) C ...
- Codeforces Round #493 (Div. 2)
C - Convert to Ones 给你一个01串 x是反转任意子串的代价 y是将子串全部取相反的代价 问全部变成1的最小代价 两种可能 一种把1全部放到一边 然后把剩下的0变成1 要么把所有的 ...
- Cutting Codeforces Round #493 (Div. 2)
Cutting There are a lot of things which could be cut — trees, paper, “the rope”. In this problem you ...
- Codeforces Round #493 (Div. 1)
A. /* 发现每次反转或者消除都会减少一段0 当0只有一段时只能消除 这样判断一下就行 */ #include<cstdio> #include<algorithm> #in ...
- Codeforces Round #493 (Div. 2)D. Roman Digits 第一道打表找规律题目
D. Roman Digits time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- 【Codeforces Round #493 (Div. 2) B】Cutting
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然只有在前i个位置奇数偶数出现次数都相同的地方才能切. (且不管前面怎么切,这里都能切的. 那么就相当于有n个物品,每个物品的代价 ...
- Codeforces Round #493 (Div. 2) A. Balloons 贪心水题
由于是输出任意一组解,可以将价值从小到大进行排序,第一个人只选第一个,第二个人选其余的.再比较一下第一个人选的元素和第二个人所选元素和是否相等即可.由于已将所有元素价值从小到大排过序,这样可以保证在有 ...
- Codeforces Round #493 (Div. 1) B. Roman Digits 打表找规律
题意: 我们在研究罗马数字.罗马数字只有4个字符,I,V,X,L分别代表1,5,10,100.一个罗马数字的值为该数字包含的字符代表数字的和,而与字符的顺序无关.例如XXXV=35,IXI=12. 现 ...
- Codeforces Round #493 (Div. 2) B. Cutting 前缀和优化_动归水题
不解释,题目过水 Code: #include<cstdio> #include<cmath> #include<algorithm> using namespac ...
随机推荐
- [SCOI2008]奖励关_状压动归_数学期望
Code: #include<cstdio> #include<algorithm> using namespace std; const int maxn = 20; dou ...
- html页面之间传值问题
1.如再A页面(A.html)通过window.open(B.html?code=11)或者通过其他方式跳转到其它html页面时: 可通过以下方式进行传递参数. //B.html页面function ...
- awk的总结
入门总结 Awk简介 awk不仅仅时linux系统中的一个命令,而且是一种编程语言,可以用来处理数据和生成报告.处理的数据可以是一个或多个文件,可以是来自标准输入,也可以通过管道获取标准输入,awk可 ...
- PHP回顾之协程
转载请注明文章出处: https://tlanyan.me/php-review... PHP回顾系列目录 PHP基础 web请求 cookie web响应 session 数据库操作 加解密 Com ...
- 设置ssh会话过期时间
客户端配置选项: 编辑配置文件 ~/.ssh/config 加入以下配置项,如不存在新建一个即可: Host * ServerAliveInterval 300 ServerAliveCountMax ...
- C# litJson 使用方法
对一般数据进行序列化和反序列化操作 static void jsonTest() { // JsonData jd = new JsonData(); jd["result"] = ...
- PatentTips - Uncore thermal management
BACKGROUND The field of invention relates to the computer sciences, generally, and, more specificall ...
- BA-siemens-insight_ppcl_adapts函数用法
adapts函数是比pid调节性更好的自适应调节算法,比pid有更好的稳定性,具有震荡小.调节过程快.平稳等特点,函数的用法如下:
- POJ 3177--Redundant Paths【无向图添加最少的边成为边双连通图 && tarjan求ebc && 缩点构造缩点树】
Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10798 Accepted: 4626 ...
- hadoop分布式架构和设计
引言 Hadoop分布式文件系统(HDFS)被设计成适合执行在通用硬件(commodity hardware)上的分布式文件系统.它和现有的分布式文件系统有非常多共同点.但同一时候,它和其它的分布式文 ...