zoukankan      html  css  js  c++  java
  • CF 493 C Convert to Ones 性质分析 + 思维

    每次肯定是对一段连续的 $0$ 或者 $1$ 进行操作. 

    对于一段连续的 $0$,要么直接变为 $1$,要么与右面的连续的 $1$ 交换. 

    如果与右面的 $1$ 翻转更加合适,那么就肯定会一直翻转,并在不能交换的时候变为 0.

    否则,就会一直将子序列变为 $0$. 

    即 $ans=min(num[0] imes y,(num[0]-1) imes 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
    ", max(1ll*0, min(1ll * a[0] * y, 1ll * (a[0] - 1) * x + y)));       
        return 0;    
    }
    

      

  • 相关阅读:
    MySQL(一)
    HTML基础
    python函数基础
    常用的模块
    面向对象进阶
    定制自己的数据类型
    Shell篇之AWK
    MATLAB如何实现傅里叶变换FFT?有何物理意义?
    傅里叶分析
    2018年度关键词
  • 原文地址:https://www.cnblogs.com/guangheli/p/9845121.html
Copyright © 2011-2022 走看看