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.
题意就是所有子串,每个子串元音比重之和,其实通过举例,可以发现是一个回形矩阵,如n = 5时,每个位置个数是
1/1 1/2 1/3 1/4 1/5
1 1 1 1 1
1 2 2 2 1
1 2 3 2 1
1 2 2 2 1
1 1 1 1 1
发现是个回形矩阵就好搞了,用sum最终的结果,s,与上一行的差值 ,s2与上一行不同的差值!这样用o(n)的时间,就可以求出解了!
#define INF 9000000000
#define EPS (double)1e-9
#define mod 1000000007
#define PI 3.14159265358979
//*******************************************************************************/
#endif
#define N 500050
#define M 100005
#define maxn 205
#define MOD 1000000000000000007
int n,dp[N];
char str[6] = { 'I','E','A','O','U','Y'},pri[N];
bool isalpho(char c){
FI(6)
if(str[i] == c)
return true;
return false;
}
int main()
{
double sum = 0,s = 0,s2 = 0;
while(SS(pri)!=EOF)
{
memset(dp,0,sizeof(dp));
sum = 0; s = 0;s2 = 0;
n = strlen(pri);
FI(n){
s+=1.0/(i+1);
}
s2 = s;
int k = (n&1)?n/2+1:n/2;
FI(n){
if(isalpho(pri[i])){
sum += s2;
}
s-= 1.0/(i + 1) + 1.0/(n- i);
s2 += s;
}
printf("%.6f\n",sum);
}
return 0;
}