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.

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.

题目链接:http://codeforces.com/contest/509/problem/E

题意:给你一个字符串,求字串中I, E, A, O, U, Y.的比例和;

   例如:BYOB  

      B  0    BY 1/2   BYO 2/3    BYOB  1/2

      Y  1     YO   1  YOB  2/3

      O 1      OB   1/2

      B  0

      0+1+1/2+2/3+1/2+1+1+2/3+1+1/2+0=5.833333

思路:显然算贡献的题;

  对于一个字符,左边有l个,右边有r个,包含其的字串总有(l+1)*(r+1)个;

  其贡献会形成一个平行四边行

  1  1/2   1/3  1/4

   1/2   1/3   1/4   1/5

  用前缀和预处理即可;

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define mk make_pair
#define eps 1e-7
#define bug(x) cout<<"bug"<<x<<endl;
const int N=5e5+,M=1e6+,inf=;
const ll INF=1e18+,mod=; /// 数组大小
char ch[]={'I','E','A','O','U','Y'},s[N];
double sum1[N],sum2[N],sum3[N];
int check(char a)
{
for(int i=;i<;i++)
if(a==ch[i])return ;
return ;
}
int main()
{
scanf("%s",s+);
int n=strlen(s+);
for(int i=;i<=n;i++)
sum1[i]=sum1[i-]+(1.0*/i);
for(int i=;i<=n;i++)
sum2[i]=sum2[i-]+sum1[i];
for(int i=n,j=;i>=;i--,j++)
sum3[j]=sum3[j-]+sum1[n]-sum1[i-];
double ans=0.0;
for(int i=;i<=n;i++)
{
if(check(s[i]))
{
int l=i;
int r=n-i+;
ans+=1.0*sum1[n]*l;
ans-=sum2[l-];
ans-=sum3[l-];
}
//cout<<ans<<endl;
}
printf("%f\n",ans);
return ;
}
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.

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.

Codeforces Round #289 (Div. 2, ACM ICPC Rules) E. Pretty Song 算贡献+前缀和的更多相关文章

  1. codeforces水题100道 第十八题 Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table (brute force)

    题目链接:http://www.codeforces.com/problemset/problem/509/A题意:f[i][1]=f[1][i]=1,f[i][j]=f[i-1][j]+f[i][j ...

  2. Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table【递推】

    A. Maximum in Table time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

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

    题目传送门 /* 题意:有 n 个piles,第 i 个 piles有 ai 个pebbles,用 k 种颜色去填充所有存在的pebbles, 使得任意两个piles,用颜色c填充的pebbles数量 ...

  4. 递推水题 Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table

    题目传送门 /* 模拟递推水题 */ #include <cstdio> #include <iostream> #include <cmath> #include ...

  5. Codeforces Round #622 (Div. 2) B. Different Rules(数学)

    Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n ...

  6. Codeforces Round #289 Div 2

    A. Maximum in Table 题意:给定一个表格,它的第一行全为1,第一列全为1,另外的数满足a[i][j]=a[i-1][j]+a[i][j-1],求这个表格中的最大的数 a[n][n]即 ...

  7. Codeforces Round #554 (Div. 2) F2. Neko Rules the Catniverse (Large Version) (矩阵快速幂 状压DP)

    题意 有nnn个点,每个点只能走到编号在[1,min(n+m,1)][1,min(n+m,1)][1,min(n+m,1)]范围内的点.求路径长度恰好为kkk的简单路径(一个点最多走一次)数. 1≤n ...

  8. Codeforces Round #381 (Div. 1) B. Alyona and a tree dfs序 二分 前缀和

    B. Alyona and a tree 题目连接: http://codeforces.com/contest/739/problem/B Description Alyona has a tree ...

  9. Codeforces Round #294 (Div. 2) D. A and B and Interesting Substrings [dp 前缀和 ]

    传送门 D. A and B and Interesting Substrings time limit per test 2 seconds memory limit per test 256 me ...

随机推荐

  1. 支持向量机:Numerical Optimization,SMO算法

    http://www.cnblogs.com/jerrylead/archive/2011/03/18/1988419.html 另外一篇:http://www.cnblogs.com/vivouni ...

  2. Windows多线程基础

    进程与线程基础 程序: 计算机指令的集合,以文件的形式存储在磁盘上 进程: 正在运行是程序实例,以是一个程序在其自身的地址空间的一次执行活动.进程有一个进程管理的内核对象和地址空间组成. 线程: 程序 ...

  3. python selenium webdriver处理浏览器滚动条

    用键盘右下角的UP,DOWN按键来处理页面滚动条 这种方法很灵活用起来很方便!!!! from selenium import webdriver import time from selenium. ...

  4. background 背景图片 在IE8中不显示解决方法

    我给ul加了一个背景图片 background 火狐 ie9 ch都显示.唯独在IE8中不显示 之前的样式代码 background: url( rgba(, , , ); 在ie8中改成 backg ...

  5. centos infiniband网卡安装配置

    硬件:Mellanox InfiniBand,主要包括 HCA(主机通道适配器)和交换机两部分 软件:CentOS 6.4 MLNX_OFED_LINUX-2.1-1.0.0-rhel6.4-x86_ ...

  6. MATERIALIZED VIEW-物化视图

     Oracle的实体化视图提供了强大的功能,可以用在不同的环境中,实体化视图和表一样可以直接进行查询.实体化视图可以基于分区表,实体化视图本身也可以分区. 主要用于预先计算并保存表连接或聚集等耗时较多 ...

  7. web前端----css选择器样式

    一.css概述 CSS是Cascading Style Sheets的简称,中文称为层叠样式表,对html标签的渲染和布局 CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明. 例如 二.c ...

  8. mysql多实例安装与ssl认证

    mysql多实例安装有两种形式: 同一数据库版本的多实例安装. 不同数据库版本的多实例安装. 同一数据库的多实例安装: 在同一台机器上安装4台mysql数据库实例. 从官网下载MySQL5.6版本的二 ...

  9. phpstudy升级mysql版本到5.7 ,重启mysql不启动

    phpstudy中mysql升级后MySQL服务无法启动 问题产生: 安装好phpstudy后,升级了MySQL后,通过phpstudy启动,Apache可以启动,Mysql无法启动. 解决方法: 之 ...

  10. SP211 PRIMIT - Primitivus recurencis(欧拉回路)

    SP211 PRIMIT - Primitivus recurencis 欧拉回路 Warning: enormous Input/Output data 警告:巨大的输入/输出 经过若干(11)次提 ...