Codeforces 509E 想法

来源:互联网 发布:php进销存管理系统 编辑:程序博客网 时间:2024/04/27 10:57

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.

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



题意:

定义一个字符串的优美度为这个字符串中元音字母所占的比例。
给定一个字符串,对这个字符串所有子串的优美度求和。


题解:我们算每个字符对所有子串的贡献  很容易得出这样的结果

1+1/2+1/3+1/4
     1/2+1/3+1/4+1/5
             1/3+1/4+1/5+1/6

那么问题就变成了求解这个平行四边形的和

预处理三角形的阶层和

把下面补齐  上面补齐  变成一个直角三角形

那么就是拿大三角形的阶层和减去上面的再减去左下角的


#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;char s[500005];double sum[500005];int len;void init(){int i=1;double d=0;for(i=1;i<=500000;i++){d+=1.0/i;sum[i]=sum[i-1]+d;}}int judge(char t){if(t=='A'||t=='I'||t=='E'||t=='U'||t=='O'||t=='Y')return 1;return 0;}double solve(int t){return sum[len]-sum[len-t]-sum[t-1];//整个-上面-左下角}int main(){init();scanf("%s",s+1);len=strlen(s+1);int i;double ans=0;for(i=1;i<=len;i++){if(judge(s[i])){ans+=solve(i);}}printf("%.8f\n",ans);return 0;}


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 头发长得特别慢怎么办 我的头发长得慢怎么办 衣服混洗染色了怎么办 黑裤子洗成红色怎么办 衣服烘干后皱了怎么办 毛衣洗了变长了怎么办 boy烫金被洗掉了怎么办 黑衣服洗得发白怎么办 黑衣服洗后发白怎么办 黑裤子洗了发白怎么办 黑衣服旧了发白怎么办 黑色衣服洗白了怎么办 黑衣服洗了泛白怎么办 刚买的衣服掉色怎么办 棉质的衣服褪色怎么办 黑裤子晒掉色了怎么办 新买的衣服褪色怎么办 衣服洗了掉毛怎么办 衣服受潮长了斑点怎么办 黑色的衣服粘毛怎么办 黑衣服容易粘毛怎么办 衣服上粘了毛毛怎么办 黑衣服防止粘毛怎么办 洗黑色衣服掉毛怎么办 兔毛的衣服掉毛怎么办 带绒的衣服掉毛怎么办 黑裤子被84掉色怎么办 买的衣服掉毛怎么办 裤子穿久了泛亮怎么办 新买的裤子褪色怎么办 黑裤子掉毛严重怎么办 黑裤子洗完发白怎么办 新买羊绒衫掉毛怎么办 皮草毛卷起来了怎么办 小孩衣服洗不干净怎么办 衣服沾上钢笔水怎么办 羊绒衫洗了掉毛怎么办 白衬衫弄上墨水怎么办 羊毛衬衫洗错了怎么办 婚纱照拍的太丑怎么办 微信加人没反应怎么办