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

原创 2015年07月08日 11:09:22
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;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

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

考虑每一位对答案的影响,然后三种情况分类讨论。。。 #include #include #include #include #include #include #include #in...

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 st...

Codeforces Round #289 (Div. 2, ACM ICPC Rules) C. Sums of Digits

贪心,找比前一位大并且各位数字和为a[i]的最小的数。。。 #include #include #include #include #include #include #include ...

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

B. Painting Pebbles time limit per test 1 second memory limit per test 256 megabytes ...

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

一月最后一场,ACM-ICPC规则,没有pretest,没有hack,原本感觉会比上次简单点。。结果把自己打成绿名了。。。 一共就出了一道题。结束之后,B题改过了。 509A - Maximum in...
  • wcr1996
  • wcr1996
  • 2015年02月01日 00:19
  • 1179

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

B. Painting Pebbles time limit per test 1 second memory limit per test 256 megabytes inpu...

Codeforces Round #289 (Div. 2, ACM ICPC Rules)C. Sums of Digits

C. Sums of Digits time limit per test 2 seconds memory limit per test 256 megabytes input...

Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E - Cubes

#include #include #include #include #include #include #include #include #include #include #include #...
  • zz_1215
  • zz_1215
  • 2012年04月22日 17:52
  • 448

Codeforces Round #116 (Div. 2, ACM-ICPC Rules)---E. Cubes

Let’s imagine that you’re playing the following simple computer game. The screen displays n lined-up...

Codeforces Round #145 (Div. 2, ACM-ICPC Rules)

编码能力实在太弱了....这次的cf前五道全是implementation问题,竟然在三个半小时内敲不出来... zigbee也让人头疼,哎... A Lefthan...
  • loinus
  • loinus
  • 2012年10月17日 10:39
  • 381
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Codeforces Round #289 (Div. 2, ACM ICPC Rules) E. Pretty Song
举报原因:
原因补充:

(最多只允许输入30个字)