CF997A Convert to Ones

题目大意:

给你一个长度为 nn 的01串( n $\leq 3*10^5$ ),你有两种操作:

1.将一个子串翻转,花费 XX

2.将一个子串中的0变成1,1变成0,花费 YY

求你将这个01串变成全是1的串的最少花费。

首先,你要操作的次数一定是这个串中0的段数,操作2覆盖消去一段0,操作1翻转将两段合并成一段

如果单纯考虑操作2,需要进行cnt次(这个串中0的段数),

如果单纯考虑操作1,需要进行cnt-1次(这个串中0的段数)+1(必须进行操作2)。

既然操作1,2的效果是一样的,那么cnt-1次就可以取最小的x,y去操作,最后再加上最后一次覆盖即可。

#include<bits/stdc++.h>

using namespace std;
string s;
int x,y,n;
int main() {
cin>>n>>x>>y;
cin>>s;
int cnt=;
s[s.length()]='';
for(int i=;i<s.length();i++){
if(s[i]==''&&s[i+]=='') ++cnt;
}
if(!cnt) printf("");
else printf("%lld",1ll*min(x,y)*(cnt-)+y);
return ;
}

CF997A Convert to Ones的更多相关文章

  1. 洛谷 CF997A Convert to Ones

    洛谷 CF997A Convert to Ones 洛谷传送门 题意翻译 给你一个长度为 nn 的01串( n \leq 310^5n*≤3∗105 ),你有两种操作: 1.将一个子串翻转,花费 XX ...

  2. 洛谷CF997A:Convert to Ones

    温馨提示: 本题适合先思考再看题解,相信各位神犇都能轻轻松松过掉它. 题目链接: https://www.luogu.com.cn/problem/CF997A 分析: 首先要读懂题,to ones, ...

  3. Convert BSpline Curve to Arc Spline in OpenCASCADE

    Convert BSpline Curve to Arc Spline in OpenCASCADE eryar@163.com Abstract. The paper based on OpenCA ...

  4. Convert.ToInt32()、int.Parse()和(int)三者的区别

    Convert.ToInt32将object类类型转换成int类型,如Convert.ToInt32(session["shuzi"]); (int)适合简单数据类型之间的转换: ...

  5. Leetcode: Convert sorted list to binary search tree (No. 109)

    Sept. 22, 2015 学一道算法题, 经常回顾一下. 第二次重温, 决定增加一些图片, 帮助自己记忆. 在网上找他人的资料, 不如自己动手. 把从底向上树的算法搞通俗一些. 先做一个例子: 9 ...

  6. [LeetCode] Convert a Number to Hexadecimal 数字转为十六进制

    Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s compl ...

  7. [LeetCode] Convert Sorted List to Binary Search Tree 将有序链表转为二叉搜索树

    Given a singly linked list where elements are sorted in ascending order, convert it to a height bala ...

  8. [LeetCode] Convert Sorted Array to Binary Search Tree 将有序数组转为二叉搜索树

    Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 这道 ...

  9. 5 Convert Sorted List to Binary Search Tree_Leetcode

    Given a singly linked list where elements are sorted in ascending order, convert it to a height bala ...

随机推荐

  1. BNUOJ 13098 约瑟夫环问题

    C. Josephus Problem 题目链接:http://www.bnuoj.com/v3/contest_show.php?cid=7095#problem/C 题目描述   The hist ...

  2. [1525] Cow Xor

    问题描述 农民约翰在喂奶牛的时候被另一个问题卡住了.他的所有N(1 <= N <= 100,000)个奶牛在他面前排成一行(按序号1..N的顺序),按照它们的社会等级排序.奶牛#1有最高的 ...

  3. JSP页面规格化

    http://doc.okbase.net/%E4%BA%BA%E7%94%9F%E9%9A%BE%E5%BE%97%E7%B3%8A%E6%B6%82/archive/123084.html htt ...

  4. (多项式)因式分解定理(Factor theorem)与多项式剩余定理(Polynomial remainder theorem)(多项式长除法)

    (多项式的)因式分解定理(factor theorem)是多项式剩余定理的特殊情况,也就是余项为 0 的情形. 0. 多项式长除法(Polynomial long division) Polynomi ...

  5. androd基础入门---1环境

    1.项目结构特性 2.模拟器设置 3.编译器的下载 直接点击运行即可

  6. [Swift通天遁地]二、表格表单-(3)在表格中嵌套另一个表格并使Cell的高度自适应

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  7. C 语言程序员必读的 5 本书

    你正通过看书来学习C语言吗?书籍是知识的丰富来源.你可以从书中学到各种知识.书籍可以毫无歧视地向读者传达作者的本意.C语言是由 Dennis Ritchie在1969年到1973年在贝尔实验室研发的. ...

  8. JavaScript Date 日期操作

    在前端工程师的道路上,可能有时候需要与时间来打交道,下面我们来看一下日常对日期的操作,今天我们介绍的是Day.js插件 Day.js 是一个轻量的处理时间和日期的 JavaScript 库,和 Mom ...

  9. Elasticsearch索引的操作,利用kibana(如何创建/删除一个es的索引?)

    我们已经通过索引一篇文档创建了一个新的索引 .这个索引采用的是默认的配置,新的字段通过动态映射的方式被添加到类型映射.现在我们需要对这个建立索引的过程做更多的控制:我们想要确保这个索引有数量适中的主分 ...

  10. strcpy 和 memcpy自实现

    都是套路,详见代码注释: #include <stdio.h> #include <assert.h> #include <iostream> using name ...