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".
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 a single integer, the wow factor of ss.
vvvovvv
4
vvovooovovvovoovoovvvvovovvvov
100
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[][] = { {,},{,-},{-,},{,} };
const int maxn = 1e5 + ;
const long long inf = 0x7f7f7f7f7f7f7f7f; int main()
{
string s;
cin >> s;
int v = , maxn = , initial = , firsto = ;
vector<ll> dp;
for (int i = ; s[i] == 'v'; i++)
initial++;
if (initial > )
dp.push_back(initial - );
else
dp.push_back();
for (int i = initial+; i < s.size(); i++)
{
if (s[i] == 'v')
maxn++;
else
{
if (maxn > )
dp.push_back(dp.back() + maxn - );
else
dp.push_back(dp.back());
maxn = ;
}
if (i == s.size() - && maxn>)
{
dp.push_back(dp.back() + maxn - );
} } ll sum = ;
for (int i = ; i < dp.size(); i++)
{
sum += (dp.back() - dp[i])*dp[i];
}
cout << sum;
return ;
}
WOW Factor的更多相关文章
- Codeforces Global Round 4 B. WOW Factor (前缀和,数学)
题意:找出序列中有多少子序列是\(wow\),但是\(w\)只能用\(vv\)来表示. 题解:我们分别记录连续的\(v\)和\(o\)的个数,用\(v1\)和\(v2\)存,这里要注意前导\(o\)不 ...
- Codeforces 1178B. WOW Factor
传送门 显然对每个 $o$ ,考虑左边和右边分别有多少 $w$,那么这个 $o$ 的贡献就是左右 $w$ 的出现次数相乘 $w$ 的出现次数可以直接根据每一段连续的 $v$ 得到 那么从左到右扫一遍, ...
- (转)iOS Wow体验 - 第八章 - 易用性与自动化技术
本文是<iOS Wow Factor:Apps and UX Design Techniques for iPhone and iPad>第八章译文精选,也是全书译文的最后一篇.上一篇:W ...
- (转)iOS Wow体验 - 第七章 - 操作图例与触屏人机工学
本文是<iOS Wow Factor:Apps and UX Design Techniques for iPhone and iPad>第七章译文精选,其余章节将陆续放出.上一篇:Wow ...
- (转)iOS Wow体验 - 第六章 - 交互模型与创新的产品概念(2)
本文是<iOS Wow Factor:Apps and UX Design Techniques for iPhone and iPad>第六章译文精选的第二部分,其余章节将陆续放出.上一 ...
- (转)iOS Wow体验 - 第六章 - 交互模型与创新的产品概念(1)
本文是<iOS Wow Factor:Apps and UX Design Techniques for iPhone and iPad>第六章译文精选,其余章节将陆续放出.上一篇:Wow ...
- (转)iOS Wow体验 - 第五章 - 利用iOS技术特性打造最佳体验
本文是<iOS Wow Factor:Apps and UX Design Techniques for iPhone and iPad>第五章译文精选,其余章节将陆续放出.上一篇:Wow ...
- (转)iOS Wow体验 - 第四章 - 为应用的上下文环境而设计
本文是<iOS Wow Factor:Apps and UX Design Techniques for iPhone and iPad>第四章译文精选,其余章节将陆续放出.上一篇:Wow ...
- (转)iOS Wow体验 - 第三章 - 用户体验的差异化策略
本文是<iOS Wow Factor:Apps and UX Design Techniques for iPhone and iPad>第三章译文精选,其余章节将陆续放出.上一篇:Wow ...
随机推荐
- 在Ubuntu中建立软连接
使用ln 命令 今天发现我的python3命令没了,出现了以下提示: /usr/bin/python3: bad interpreter: No such file or directory 查找原因 ...
- 关于华为高斯数据库 GaussDB 版本及认证体系介绍
目录 你需要知道的 技术有国界 从它的名称说起 你听到过的版本 你听到过的流言蜚语 各个版本的区别 版本未来名称 华为 GaussDB 认证体系介绍 GaussDB 其他资料相关链接 你需要知道的 任 ...
- Win10下安装tensorflow详细过程
首先声明几点: 安装tensorflow是基于Python的,并且需要从Anaconda仓库中下载. 所以我们的步骤是:先下载Anaconda,再在Anaconda中安装一个Python,(你的电脑里 ...
- Extreme Learning Machine
Extreme Learning Machine 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 1. ELM 2004年南洋理工大学黄广斌提出了ELM ...
- [转] c# 中使用opencv进行视频捕获
简介 这个项目是关于如何从网络摄像头或者视频文件(*.AVI)中捕获视频的,这个项目是用C#和OPENCV编写的. 这将有助于那些喜欢C#和OpenCV环境的人.这个程序完全基于Visual Stud ...
- linux安装samba服务器
1- samba介绍 Samba 是在 Linux 和 UNIX 系统上实现 SMB 协议的一个免费软 件,由服务器及客户端程序构成,SMB(Server Messages Block,信息服务块)是 ...
- 2019ICPC南昌站E.Bob's Problem
题意: 一张图,n个点,m条边分为黑边和白边,黑边任意选,白边只能选k条,在保持整张图连通的情况下使得所选变的权值和最大 解析: 因为边权全部是正值,所以可以把黑边全选上,缩点之后对各个连通块和白边进 ...
- Xamarin.Android 开发,生成时提示“Resource.Drawable”未包含“BG”的定义
Xamarin Android提示Resource.Drawable”未包含“BG”的定义错误信息:error CS0117: '“Resource.Drawable”未包含“BG”的定义Xamari ...
- mybatis一级缓存和二级缓存(一)
一级缓存: 就是Session级别的缓存.一个Session做了一个查询操作,它会把这个操作的结果放在一级缓存中. 如果短时间内这个session(一定要同一个session)又做了同一个操作,那么h ...
- PP: Toeplitz Inverse Covariance-Based Clustering of Multivariate Time Series Data
From: Stanford University; Jure Leskovec, citation 6w+; Problem: subsequence clustering. Challenging ...