E. Pretty Song
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

When Sasha was studying in the seventh grade, he started listening to music a lot. In order to evaluate which songs he likes more, he introduced the notion of the song's prettiness. The title of the song is a word consisting of uppercase Latin letters. The prettiness of the song is the prettiness of its title.

Let's define the simple prettiness of a word as the ratio of the number of vowels in the word to the number of all letters in the word.

Let's define the prettiness of a word as the sum of simple prettiness of all the substrings of the word.

More formally, let's define the function vowel(c) which is equal to 1, if c is a vowel, and to 0 otherwise. Let si be the i-th character of string s, and si..j be the substring of word s, staring at the i-th character and ending at the j-th character (sisi + 1... sji ≤ j).

Then the simple prettiness of s is defined by the formula:

The prettiness of s equals

Find the prettiness of the given song title.

We assume that the vowels are I, E, A, O, U, Y.

Input

The input contains a single string s (1 ≤ |s| ≤ 5·105) — the title of the song.

Output

Print the prettiness of the song with the absolute or relative error of at most 10 - 6.

Examples
input
IEAIAIO
output
28.0000000
input
BYOB
output
5.8333333
input
YISVOWEL
output
17.0500000
Note

In the first sample all letters are vowels. The simple prettiness of each substring is 1. The word of length 7 has 28 substrings. So, the prettiness of the song equals to 28.

题目链接:http://codeforces.com/contest/509/problem/E

题意:给你一个字符串,求字串中I, E, A, O, U, Y.的比例和;

   例如:BYOB  

      B  0    BY 1/2   BYO 2/3    BYOB  1/2

      Y  1     YO   1  YOB  2/3

      O 1      OB   1/2

      B  0

      0+1+1/2+2/3+1/2+1+1+2/3+1+1/2+0=5.833333

思路:显然算贡献的题;

  对于一个字符,左边有l个,右边有r个,包含其的字串总有(l+1)*(r+1)个;

  其贡献会形成一个平行四边行

  1  1/2   1/3  1/4

   1/2   1/3   1/4   1/5

  用前缀和预处理即可;

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define mk make_pair
#define eps 1e-7
#define bug(x) cout<<"bug"<<x<<endl;
const int N=5e5+,M=1e6+,inf=;
const ll INF=1e18+,mod=; /// 数组大小
char ch[]={'I','E','A','O','U','Y'},s[N];
double sum1[N],sum2[N],sum3[N];
int check(char a)
{
for(int i=;i<;i++)
if(a==ch[i])return ;
return ;
}
int main()
{
scanf("%s",s+);
int n=strlen(s+);
for(int i=;i<=n;i++)
sum1[i]=sum1[i-]+(1.0*/i);
for(int i=;i<=n;i++)
sum2[i]=sum2[i-]+sum1[i];
for(int i=n,j=;i>=;i--,j++)
sum3[j]=sum3[j-]+sum1[n]-sum1[i-];
double ans=0.0;
for(int i=;i<=n;i++)
{
if(check(s[i]))
{
int l=i;
int r=n-i+;
ans+=1.0*sum1[n]*l;
ans-=sum2[l-];
ans-=sum3[l-];
}
//cout<<ans<<endl;
}
printf("%f\n",ans);
return ;
}
E. Pretty Song
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

When Sasha was studying in the seventh grade, he started listening to music a lot. In order to evaluate which songs he likes more, he introduced the notion of the song's prettiness. The title of the song is a word consisting of uppercase Latin letters. The prettiness of the song is the prettiness of its title.

Let's define the simple prettiness of a word as the ratio of the number of vowels in the word to the number of all letters in the word.

Let's define the prettiness of a word as the sum of simple prettiness of all the substrings of the word.

More formally, let's define the function vowel(c) which is equal to 1, if c is a vowel, and to 0 otherwise. Let si be the i-th character of string s, and si..j be the substring of word s, staring at the i-th character and ending at the j-th character (sisi + 1... sji ≤ j).

Then the simple prettiness of s is defined by the formula:

The prettiness of s equals

Find the prettiness of the given song title.

We assume that the vowels are I, E, A, O, U, Y.

Input

The input contains a single string s (1 ≤ |s| ≤ 5·105) — the title of the song.

Output

Print the prettiness of the song with the absolute or relative error of at most 10 - 6.

Examples
input
IEAIAIO
output
28.0000000
input
BYOB
output
5.8333333
input
YISVOWEL
output
17.0500000
Note

In the first sample all letters are vowels. The simple prettiness of each substring is 1. The word of length 7 has 28 substrings. So, the prettiness of the song equals to 28.

Codeforces Round #289 (Div. 2, ACM ICPC Rules) E. Pretty Song 算贡献+前缀和的更多相关文章

  1. codeforces水题100道 第十八题 Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table (brute force)

    题目链接:http://www.codeforces.com/problemset/problem/509/A题意:f[i][1]=f[1][i]=1,f[i][j]=f[i-1][j]+f[i][j ...

  2. Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table【递推】

    A. Maximum in Table time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. 贪心 Codeforces Round #289 (Div. 2, ACM ICPC Rules) B. Painting Pebbles

    题目传送门 /* 题意:有 n 个piles,第 i 个 piles有 ai 个pebbles,用 k 种颜色去填充所有存在的pebbles, 使得任意两个piles,用颜色c填充的pebbles数量 ...

  4. 递推水题 Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table

    题目传送门 /* 模拟递推水题 */ #include <cstdio> #include <iostream> #include <cmath> #include ...

  5. Codeforces Round #622 (Div. 2) B. Different Rules(数学)

    Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n ...

  6. Codeforces Round #289 Div 2

    A. Maximum in Table 题意:给定一个表格,它的第一行全为1,第一列全为1,另外的数满足a[i][j]=a[i-1][j]+a[i][j-1],求这个表格中的最大的数 a[n][n]即 ...

  7. Codeforces Round #554 (Div. 2) F2. Neko Rules the Catniverse (Large Version) (矩阵快速幂 状压DP)

    题意 有nnn个点,每个点只能走到编号在[1,min(n+m,1)][1,min(n+m,1)][1,min(n+m,1)]范围内的点.求路径长度恰好为kkk的简单路径(一个点最多走一次)数. 1≤n ...

  8. Codeforces Round #381 (Div. 1) B. Alyona and a tree dfs序 二分 前缀和

    B. Alyona and a tree 题目连接: http://codeforces.com/contest/739/problem/B Description Alyona has a tree ...

  9. Codeforces Round #294 (Div. 2) D. A and B and Interesting Substrings [dp 前缀和 ]

    传送门 D. A and B and Interesting Substrings time limit per test 2 seconds memory limit per test 256 me ...

随机推荐

  1. python2与python3之间的主要区别

    python2与python3之间的主要区别 print py2:print语句,语句就意味着可以直接跟要打印的东西,如果后面接的是一个元组对象,直接打印 py3:print函数,函数就以为这必须要加 ...

  2. HTTP 教程

    HTTP 简介 HTTP协议(HyperText Transfer Protocol,超文本传输协议)是因特网上应用最为广泛的一种网络传输协议,所有的WWW文件都必须遵守这个标准. HTTP是一个基于 ...

  3. Java序列化总结

    什么是序列化? 序列化是将对象的状态信息转化为可以存储或传输的形式的过程.在序列化期间,对象将其当前状态写入到临时或持久性存储区.以后可以通过存储区中读取或反序列化对象的状态重新创建对象. 为什么要序 ...

  4. python直接赋值、浅拷贝和深拷贝

    # 解: # import copy # names1=['Amir','Barry','Cgakes','Dao',[11,22,33]] # names2=names1#直接赋值,指向同一个对象 ...

  5. 020-安装centos6.5后的生命历程

    01.配置网络.修改了ifcfg-eth0文件内容. 1)ifcfg-eth0原来的内容如下: 2)ifcfg-eth0配置后的内容如下:   3)然后重启网络服务: 4)测试网络是否可通: 5)查看 ...

  6. Verilog篇(三)仿真原理

    首先引入一个例子: `timescale  1ns/100ps module   TB;                                                         ...

  7. eclipse设置字体、字符编码、快捷键

    1.设置字体: preferences->general->appearnce->colors and fonts->edit->字体大小14,字形常规,字体Consol ...

  8. Codeforces 1146E Hot is Cold

    题意: 给出一个序列,有两种操作: \(>\;x\) 将大于\(x\)的数全都取负 \(<\;x\) 将小于\(x\)的数全都取负 最后输出序列中的所有数最后的状态 思路: 我们先考虑对于 ...

  9. KM算法模板

    大白书P248有证明,此处贴出两种复杂度的方案, n^4 大白书P350 n^3 #include <algorithm> #include <string.h> #inclu ...

  10. Python: 字典列表: itemgetter 函数: 根据某个或某几个字典字段来排序列表

    问题:根据某个或某几个字典字段来排序Python列表 answer: 通过使用operator 模块的itemgetter 函数,可以非常容易的排序这样的数据结构 eg: rows = [ {'fna ...