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

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.

Examples
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, the prettiness of the song equals to 28.

一开始完全没有思路……但是后来想着想着就出来一个O(N)的。要用到预处理。(假设字符串长度为N) 首先把那些元音字母的位置筛出来。

我的代码中的ai表示(1/1+1/N) + (2/2+2/(N-1)) + ... + (i/i+i/(N-i+1)) bi表示1/1+1/2+1/3+...+1/i  (之后我会解释为什么要这样预处理)

每次对于一个元音字母的位置x,无论他在该字符串的前一半还是字符串的后一半,都把他调到前一半的对称位置。(比如说输入的字符串长度为6,我现在要处理的元音字母的位置为5,那么就可以等效成2),然后利用等效之后的这个x生成一个序列,这个序列是分数,长度为N,其中分母为1,2,3,4,...,N,分子为1,2,3,....,x-1,x,x,x,x-1,...,3,2,1(对就是这样的一个序列现在我们要计算这个序列的和),就利用之前预处理出来的a数组和b数组,在O(1)内就可以实现,然后把每次得到的这个和累加起来,结果就是答案。

     #include <bits/stdc++.h>  

     using namespace std;  

     #define REP(i,n)                for(int i(0); i <  (n); ++i)
#define rep(i,a,b) for(int i(a); i <= (b); ++i)
#define dec(i,a,b) for(int i(a); i >= (b); --i)
#define for_edge(i,x) for(int i = H[x]; i; i = X[i]) const int N = + ;
const int M = + ;
const int Q = + ;
const int A = + ; char s[N];
int len, cnt;
int c[N];
double a[N], b[N];
int l, r;
double ans;
int x; int main(){ scanf("%s", s + );
len = strlen(s + ); cnt = ; l = ; r = len + ;
a[] = b[] = ;
rep(i, , len) b[i] = b[i - ] + (double) / (double)i; if (len & ){
rep(i, , len >> ){
++l, --r;
a[i] = a[i - ] + i / (double)l + i / (double)r;
}
a[len / + ] = a[len / ] + (++l) / (len / + );
}
else{
rep(i, , len >> ){
++l, --r;
a[i] = a[i - ] + i / (double)l + i / (double)r;
}
} rep(i, , len){
if (s[i] == 'A' || s[i] == 'E' || s[i] == 'I' || s[i] == 'O' || s[i] == 'U' || s[i] == 'Y'){
c[++cnt] = i;
}
} ans = ;
rep(i, , cnt){
x = c[i];
if (x > len / ) x = len - x + ;
if (x <= len / ) ans += a[x] + (b[len - x] - b[x]) * x;
else ans += a[x];
} printf("%.7f\n", ans); return ; }

Codeforces 509E Pretty Song (思维)的更多相关文章

  1. Codeforces 509E(思维)

                                                                                                         ...

  2. Educational Codeforces Round 60 C 思维 + 二分

    https://codeforces.com/contest/1117/problem/C 题意 在一个二维坐标轴上给你一个起点一个终点(x,y<=1e9),然后给你一串字符串代表每一秒的风向, ...

  3. Educational Codeforces Round 61 F 思维 + 区间dp

    https://codeforces.com/contest/1132/problem/F 思维 + 区间dp 题意 给一个长度为n的字符串(<=500),每次选择消去字符,连续相同的字符可以同 ...

  4. [Codeforces 1178D]Prime Graph (思维+数学)

    Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是 ...

  5. Sorted Adjacent Differences(CodeForces - 1339B)【思维+贪心】

    B - Sorted Adjacent Differences(CodeForces - 1339B) 题目链接 算法 思维+贪心 时间复杂度O(nlogn) 1.这道题的题意主要就是让你对一个数组进 ...

  6. Codeforces 675C Money Transfers 思维题

    原题:http://codeforces.com/contest/675/problem/C 让我们用数组a保存每个银行的余额,因为所有余额的和加起来一定为0,所以我们能把整个数组a划分为几个区间,每 ...

  7. Mike and distribution CodeForces - 798D (贪心+思维)

    题目链接 TAG: 这是我近期做过最棒的一道贪心思维题,不容易想到,想到就出乎意料. 题意:给定两个含有N个正整数的数组a和b,让你输出一个数字k ,要求k不大于n/2+1,并且输出k个整数,范围为1 ...

  8. Codeforces 1090D - Similar Arrays - [思维题][构造题][2018-2019 Russia Open High School Programming Contest Problem D]

    题目链接:https://codeforces.com/contest/1090/problem/D Vasya had an array of n integers, each element of ...

  9. Maximal GCD CodeForces - 803C (数论+思维优化)

    C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...

随机推荐

  1. callback回调函数【转】

    请给作者点赞--> 原文链接 什么是回调函数? 我们绕点远路来回答这个问题. 编程分为两类:系统编程(system programming)和应用编程(application programmi ...

  2. LINQ体验(9)——LINQ to SQL语句之Insert/Update/Delete操作

    我们继续讲解LINQ to SQL语句,这篇我们来讨论Insert/Update/Delete操作.这个在我们的程序中最为常用了.我们直接看例子. Insert/Update/Delete操作 插入( ...

  3. 程序集链接器(AL.exe)

    AL.exe使用程序可以生成一个EXE文件或者DLL PE文件(其中只包含对其他模块中的类型进行描述的一个清单). 不要在普通的命令行窗口中编译,请先打开C:\ProgramData\Microsof ...

  4. IOS开发学习笔记043-QQ聊天界面实现

    QQ聊天界面实现 效果如下: 实现过程: 1.首先实现基本界面 头像使用 UIImageView : 文字消息使用 UIButton 标签使用 UILable :水平居中 所有元素在一个cell中,在 ...

  5. Xmanager用法(export DISPLAY=客户端IP:0.0)

    1.在用户的目录下找到文件.bash_profile或profile,用vi对其进行编辑.加入下列命令行: DISPLAY=192.168.88.71:0.0;export DISPLAY 2.如果只 ...

  6. 文件处理之复杂,在于内置方法-----python

    抛砖引玉: 文件是我们储存信息的地方,我们经常要对文件进行读.写.删除等的操作,在Python中,我们可用Python提供的函数和方法方便地操作文件. ************************ ...

  7. Ubuntu下建立Pycharm快捷方式

    修改 Exec, Icon 路径,将文件保存 pycharm.desktop,拖到unity侧边栏 [Desktop Entry]Categories=Development;Comment[zh_C ...

  8. NodeJS npm 包装包失败的解决方案

    这个也是网上搜的,亲自试过,非常好用! 镜像使用方法(三种办法任意一种都能解决问题,建议使用第三种,将配置写死,下次用的时候配置还在): 1.通过config命令 npm config set reg ...

  9. 编译linux kernel及制作initrd ( by quqi99 )

    编译linux kernel及制作initrd ( by quqi99 ) 作者:张华  发表于:2013-01-27    ( http://blog.csdn.net/quqi99 ) 运行一个l ...

  10. Educational Codeforces Round 22 E. Army Creation(分块好题)

    E. Army Creation time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...