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 ...
随机推荐
- Win7系统无法记住网络访问的凭据怎么办?
访问内网其他IP时已经打勾记住我的凭据了,但是注销或者重启Win7系统之后,又得重新输入用户名跟密码怎么办? 下面就为大家介绍一下如何让Win7系统记住网络访问的凭据. 以上问题还会引发,重启后无法正 ...
- day34-1 面向对象概述
目录 面向对象编程 面向过程&面向对象 Python中一切皆对象 什么是对象? 面向对象编程 面向过程&面向对象 都是一种解决问题的思想 面向过程:在解决问题的时候,关注的是解决问题的 ...
- WEBGL学习【三】颜色选择
<html lang="zh-CN"> <head> <title>NeHe's WebGL</title> <meta ch ...
- laravel 运行migrate报错 1071 Specified key was too long
转自:https://segmentfault.com/a/1190000008416200 laravel运行命令migrate时报错: 1071 Specified key was too lo ...
- 跳出$.each()循环
return false:将停止循环 ,跳出eachreturn true:跳至下一个循环(就像在普通的循环中使用'continue').
- Struts2校验
struts2校验有两种实现方法: 手工编写代码实现(基本验证) //login.jsp <font color="red"><s:fielderror/> ...
- oracle自定义判断是否数字函数isNumber()
右击function选择新增 如果是数字返回本身,如果不是数字返回0: create or replace function isNumber(p in varchar2) return number ...
- javascript操作window对象
document.defaultView或全局变量window--获取一个window对象. 1)获取窗体信息 innerHeight.innerWidth--获取窗体内容区域的高度.宽度. oute ...
- xcodeproj cannot be opened because the project file cannot be parsed.
解决方法: 1.对.xcodeproj文件右键,显示包内容 2.双击打开 project.pbxproj 文件 3.找到以上类似的冲突信息(能够用commad + f搜索) 4.删除<&l ...
- PHP生成二维码的2种方式
二维码的用处俺也就不说了,看一下用PHP生成的二维码吧. 利用谷歌提供的API 生成二维码,如今非常多国外站点都提供了这类API 看下代码吧<=======================> ...