Codeforces Global Round 4 Problem-B. WOW Factor

B. WOW Factor: http://codeforces.com/contest/1178/problem/B

题意:

Bob的键盘坏了,只能用vv代表w,只有两个相邻的vv才能表示w。现在有一个字符串,问能否通多删减,但不改变相对顺序来得到vvovv来表示wow,如果可以问有多少个?

分析:

首先通过遍历字符串打表,建立起一个 x1ox2ox3ox4 这样的格式。x1表示在第一个o之前有多少个vv,x2表示在第二个o之前有多少个vv,以此类推。最后计算每一个o对应的左右两边的vv个数, 然后算出在这个o的基础上能有多少个wow。

code:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e6+7;

char s[N];
vector<int> ve;

int main()
{
    while(scanf("%s", s) != EOF)
    {
        ve.clear();
        ve.resize(1);
        int len = strlen(s);
        int ind = 0;
        int sum = 0;    // vv总数
        for(int i=1; i<len; i++)    // 遍历字符串,打表计算vv个数
        {
            if(s[i] == 'v' && s[i-1] == 'v')
            {
                ve[ind] ++;
                sum ++;
            }
            else if(s[i] == 'o')
            {
                ve.resize(ind+2+1); // 每遇到一个o都要往后增加两个,一个存o,一个存vv个数
                ve[ind+1] = -1; // o标记为-1
                ind += 2;       // 下标要越过o
            }
        }
        int front = 0;  // 当前o之前有多少个vv
        LL ans = 0;
        int lenv = ve.size();
        for(int i=0; i<lenv; i++)
        {
            if(ve[i] != -1)
            {
                front += ve[i];
            }
            else
            {
                ans += 1LL * front * (sum - front);
            }
                
        }
        printf("%lld\n", ans);
    }


    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Educational Codeforces Round 146 (Rated for Div. 2)比赛中,有关于一个节点数量为n的问题。根据引用的结论,无论节点数量是多少,都可以将其分成若干个大小为2或3的区间使其错排,从而减少花费。根据引用的推导,我们可以通过组合数和差量来表示剩余的花费。而引用进一步推广了这个结论,可以使得任意长度的一段错排花费代价为边权和的两倍,并且通过贪心算法使得更多的边不被使用。以此来解决与节点数量相关的问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Educational Codeforces Round 146 (Rated for Div. 2)(B,E详解)](https://blog.csdn.net/TT6899911/article/details/130044099)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [Educational Codeforces Round 83 (Rated for Div. 2) D](https://download.csdn.net/download/weixin_38562130/14878888)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值