zoukankan      html  css  js  c++  java
  • WOW Factor

    Recall that string aa is a subsequence of a string bb if aa can be obtained from bb by deletion of several (possibly zero or all) characters. For example, for the string aa="wowwo", the following strings are subsequences: "wowwo", "wowo", "oo", "wow", "", and others, but the following are not subsequences: "owoo", "owwwo", "ooo".

    The wow factor of a string is the number of its subsequences equal to the word "wow". Bob wants to write a string that has a large wow factor. However, the "w" key on his keyboard is broken, so he types two "v"s instead.

    Little did he realise that he may have introduced more "w"s than he thought. Consider for instance the string "ww". Bob would type it as "vvvv", but this string actually contains three occurrences of "w":

    • "vvvv"
    • "vvvv"
    • "vvvv"

    For example, the wow factor of the word "vvvovvv" equals to four because there are four wows:

    • "vvvovvv"
    • "vvvovvv"
    • "vvvovvv"
    • "vvvovvv"

    Note that the subsequence "vvvovvv" does not count towards the wow factor, as the "v"s have to be consecutive.

    For a given string ss, compute and output its wow factor. Note that it is not guaranteed that it is possible to get ss from another string replacing "w" with "vv". For example, ss can be equal to "vov".

    Input

    The input contains a single non-empty string ss, consisting only of characters "v" and "o". The length of ss is at most 106106.

    Output

    Output a single integer, the wow factor of ss.

    Examples
    input
    Copy
    vvvovvv
    
    output
    Copy
    4
    
    input
    Copy
    vvovooovovvovoovoovvvvovovvvov
    
    output
    Copy
    100
    
    Note

    The first example is explained in the legend.


    刚开始忘了两个int相加还是int,只用了一个longlong的sum,导致溢出。

    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <set>
    #include <queue>
    #include <map>
    #include <sstream>
    #include <cstdio>
    #include <cstring>
    #include <numeric>
    #include <cmath>
    #include <unordered_set>
    #include <unordered_map>
    #include <xfunctional>
    #define ll long long
    #define mod 998244353
    using namespace std;
    int dir[4][2] = { {0,1},{0,-1},{-1,0},{1,0} };
    const int maxn = 1e5 + 5;
    const long long inf = 0x7f7f7f7f7f7f7f7f;
    
    int main()
    {
        string s;
        cin >> s;
        int v = 0, maxn = 0, initial = 0, firsto = 0;
        vector<ll> dp;
        for (int i = 0; s[i] == 'v'; i++)
            initial++;
        if (initial > 0)
            dp.push_back(initial - 1);
        else
            dp.push_back(0);
        for (int i = initial+1; i < s.size(); i++)
        {
            if (s[i] == 'v')
                maxn++;
            else
            {
                if (maxn > 1)
                    dp.push_back(dp.back() + maxn - 1);
                else
                    dp.push_back(dp.back());
                maxn = 0;
            }
            if (i == s.size() - 1 && maxn>1)
            {
                dp.push_back(dp.back() + maxn - 1);
            }
                
        }
    
        ll sum = 0;
        for (int i = 0; i < dp.size(); i++)
        {
            sum += (dp.back() - dp[i])*dp[i];
        }
        cout << sum;
        return 0;
    }
  • 相关阅读:
    CRM 常用SQL 脚本
    Dynamic CRM 2013学习笔记(十七)JS读写各种类型字段方法及技巧
    Winform Treeview 排序及图标处理
    Dynamic CRM 2013学习笔记(十六)用JS控制Tab可见,可用
    sql server 小技巧(3) SQL Server 2012 数据库完整导出到SQL Azure (包括数据)
    解决iOS Xcode 模拟器键盘不弹出
    iOS核心动画
    PS中怎么给图层解锁
    Cocos2d-x设置吞没单击属性来避免精灵重叠被点击后的事件续传
    解决Cocos2d-x编译错误: 无法打开 源 文件 "extensions/ExtensionExport.h"
  • 原文地址:https://www.cnblogs.com/dealer/p/12345905.html
Copyright © 2011-2022 走看看