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... sj, i ≤ 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.
The input contains a single string s (1 ≤ |s| ≤ 5·105) — the title of the song.
Print the prettiness of the song with the absolute or relative error of at most 10 - 6.
IEAIAIO
28.0000000
BYOB
5.8333333
YISVOWEL
17.0500000
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, theprettiness of the song equals to 28.
题意:
定义一个字符串的优美度为这个字符串中元音字母所占的比例。
给定一个字符串,对这个字符串所有子串的优美度求和。
题解:我们算每个字符对所有子串的贡献 很容易得出这样的结果
1+1/2+1/3+1/4
1/2+1/3+1/4+1/5
1/3+1/4+1/5+1/6
那么问题就变成了求解这个平行四边形的和
预处理三角形的阶层和
把下面补齐 上面补齐 变成一个直角三角形
那么就是拿大三角形的阶层和减去上面的再减去左下角的
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s[500005];
double sum[500005];
int len;
void init(){
int i=1;
double d=0;
for(i=1;i<=500000;i++){
d+=1.0/i;
sum[i]=sum[i-1]+d;
}
}
int judge(char t){
if(t=='A'||t=='I'||t=='E'||t=='U'||t=='O'||t=='Y')return 1;
return 0;
}
double solve(int t){
return sum[len]-sum[len-t]-sum[t-1];//整个-上面-左下角
}
int main(){
init();
scanf("%s",s+1);
len=strlen(s+1);
int i;
double ans=0;
for(i=1;i<=len;i++){
if(judge(s[i])){
ans+=solve(i);
}
}
printf("%.8f\n",ans);
return 0;
}