Codeforces Round #289 (Div. 2, ACM ICPC Rules) E. Pretty Song

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.

Sample test(s)
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, 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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值