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 ...
随机推荐
- gulp常用插件之gulp-plumber使用
更多gulp常用插件使用请访问:gulp常用插件汇总 gulp-plumber这是一款防止因gulp插件的错误而导致管道中断,plumber可以阻止 gulp 插件发生错误导致进程退出并输出错误日志. ...
- [Python]爬取首都之窗百姓信件网址id python 2020.2.13
经人提醒忘记发网址id的爬取过程了, http://www.beijing.gov.cn/hudong/hdjl/com.web.consult.consultDetail.flow?original ...
- PAT (Basic Level) Practice (中文)1033 旧键盘打字 (20 分)
旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现.现在给出应该输入的一段文字.以及坏掉的那些键,打出的结果文字会是怎样? 输入格式: 输入在 2 行中分别给出坏掉的那些键.以及应该输入 ...
- V-Box
Not ) (VERR_NEM_NOT_AVAILABLE). VT-x is disabled in the BIOS for all CPU modes (VERR_VMX_MSR_ALL_VMX ...
- mysql 数据库优化的几种方法
1.选取最适用的字段属性 MySQL可以很好的支持大数据量的存取,但是一般说来,数据库中的表越小,在它上面执行的查询也就会越快.因此,在创建表的时候,为了获得更好的性能,我们可以将表中字段的宽度设得尽 ...
- A*模板(求K短路)(POJ2449)
A*是bfs的优化,IDA*是dfs的优化 A*算法: 为启发式算法中很重要的一种,被广泛应用在最优路径求解和一些策略设计的问题中.而A*算法最为核心的部分,就在于它的一个估值函数的设计上: f(n) ...
- 使用Windows实现数据绑定
一.绑定下拉框数据 string sql = "select * from Grade"; SqlDataAdapter sda = new SqlDataAdapter(sql, ...
- Mysql快速入门(二)
多表关联查询 JOIN 按照功能大致分为如下三类: CROSS JOIN(交叉连接) INNER JOIN(内连接或等值连接). OUTER JOIN(外连接) 交叉连接 交叉连接的关键字:CROSS ...
- java - CAS及CAS底层原理
CAS是什么? CAS的全称为Compare-And-Swap它是一条CPU并发原语,也就是在CPU硬件层面上来说比较并且判断是否设置新值这段操作是原子性的,不会被其他线程所打断.在JAVA并发包ja ...
- py 二级习题(turtle)
用turtle画一个正方形 import turtle turtle.penup() turtle.goto(-100,-100) turtle.pendown() turtle.begin_fill ...