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 ...
随机推荐
- c#获取所有枚举
获取所有的枚举 1.将所有的枚举单独成一个项目 2.通Assembly加载程序集 3.通过Assembly对象的GetTypes获取所有的枚举类型 4.通过Enum.GetValues可以得到枚举的所 ...
- 《The good doctor》视频笔记
第一季 第一弹可以看 角色 肖恩莫非 梅伦德斯 克莱尔·布朗 贾里德·卡鲁 道格拉斯院长 卡莉 青木 一个很厉害的女实习医生,忘记名字了 病理知识 自闭症:由于神经系统失调导致的发育障碍,其病征包括不 ...
- [PAT] A1020 Tree Traversals
[题目] distinct 不同的 postorder 后序的 inorder 中序的 sequence 顺序:次序:系列 traversal 遍历 题目大意:给出二叉树的后序遍历和中序遍历,求层次遍 ...
- ASP.NET常用内置对象(三)Server
Server对象是HttpServerUtility的一个实例,也是上下文对象HttpContext的一个属性,提供用于处理Web请求的Helper方法. Server.MapPath("& ...
- 0级搭建类012-Windows Server 2019安装(2019) 公开
项目文档引子系列是根据项目原型,制作的测试实验文档,目的是为了提升项目过程中的实际动手能力,打造精品文档AskScuti. 项目文档引子系列目前不对外发布,仅作为博客记录.如学员在实际工作过程中需提前 ...
- 根据指定id取出数组中指定对象
// 需求:根据Id取出数组中指定的对象 let arr = [ { id: 1, rotationAngle: 330, target: '目标1' }, { id: 2, rotationAngl ...
- mysql之数据初始化update操作
1.单表的:update user set name = (select name from user where id in (select id from user where name='小苏' ...
- Apache Tomcat配置启动
文章目录 前提 配置启动Tomcat 遇到的问题 端口被占用 解决方案 淇℃伅 特别感谢 前提 已经安装Java JDK 已经配置将Java JDK的bin目录添加至环境变量Path 已经配置JAVA ...
- 杭电oj_2058——The sum problem(java实现)
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2058 思路:等差数列公式变形:sum = a1 * len + len *(len -1)/2 抽象成 ...
- JS调用函数的两种方式
<script type="text/javascript"> window.onload = init; //onload 表示页面全部加载完毕后,再调用init() ...