【第21期】观点:人工智能到底用 GPU?还是用 FPGA?

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

E. Pretty Song time limit per test 1 second memory limit per test 256 megabytes inp...

Codeforces Round #116 (Div. 2, ACM-ICPC Rules) D - Name

这题细节真多!!!! #include<iostream> #include<vector> #include<algorithm> #include<cstdio> #include<queue> #include<stack> #include<string> #include<map> #include<set&gt

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

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

#include<iostream> #include<vector> #include<algorithm> #include<cstdio> #include<queue> #include<stack> #include<string> #include<map> #include<set> #include<cmath> #include<cassert> #include&

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

A. Maximum in Table time limit per test 2 seconds memory limit per test 256 megabytes ...
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

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