Codeforces Round #289 (Div. 2, ACM ICPC Rules) E. Pretty Song 算贡献+前缀和

时间:2022-12-24 10:49:58
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:

Codeforces Round #289 (Div. 2, ACM ICPC Rules) E. Pretty Song 算贡献+前缀和

The prettiness of s equals

Codeforces Round #289 (Div. 2, ACM ICPC Rules) E. Pretty Song 算贡献+前缀和

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:

Codeforces Round #289 (Div. 2, ACM ICPC Rules) E. Pretty Song 算贡献+前缀和

The prettiness of s equals

Codeforces Round #289 (Div. 2, ACM ICPC Rules) E. Pretty Song 算贡献+前缀和

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 &num;289 &lpar;Div&period; 2&comma; ACM ICPC Rules&rpar; A&period; Maximum in Table &lpar;brute force&rpar;

    题目链接: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 &num;289 &lpar;Div&period; 2&comma; ACM ICPC Rules&rpar; A&period; Maximum in Table【递推】

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

  3. 贪心 Codeforces Round &num;289 &lpar;Div&period; 2&comma; ACM ICPC Rules&rpar; B&period; Painting Pebbles

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

  4. 递推水题 Codeforces Round &num;289 &lpar;Div&period; 2&comma; ACM ICPC Rules&rpar; A&period; Maximum in Table

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

  5. Codeforces Round &num;622 &lpar;Div&period; 2&rpar; B&period; Different Rules(数学)

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

  6. Codeforces Round &num;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 &num;554 &lpar;Div&period; 2&rpar; F2&period; Neko Rules the Catniverse &lpar;Large Version&rpar; (矩阵快速幂 状压DP)

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

  8. Codeforces Round &num;381 &lpar;Div&period; 1&rpar; B&period; 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 &num;294 &lpar;Div&period; 2&rpar; D&period; A and B and Interesting Substrings &lbrack;dp 前缀和 &rsqb;

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

随机推荐

  1. iOS UIGestureRecognizer与UIMenuController(内容根据iOS编程)

    UIGestureRecognizer 对象会截取本应由视图处理的触摸事件.当某个UIGestureRecognizer对象识别出特定的手势后,就会向指定的对象发送指定的消息.iOS SDK默认提供若 ...

  2. BZOJ 1014 【JSOI2008】 火星人prefix

    Description 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字符予以标号:序号: 1 2 3 4 5 6 7 ...

  3. O&lowbar;NONBLOCK on regular file

    It seems that writes/reads to regular files can't not be made non-blocking. I found the following re ...

  4. UOJ 217 奇怪的线段树

    http://uoj.ac/problem/217 题意就不X了,思路在这: 居然一开始把sap里面的mn设置为inf了,我是傻逼.. #include<cstdio> #include& ...

  5. C&plus;&plus;&comma;Python&comma;Go对照学习-01

    好吧其实学Go只是为了好玩,只是为了好玩,学习过程中不免会把其他我懂的语言的思维定势和习惯带进来,由此有了这篇对照学习的记录,就当是留下学习的脚印吧. 这里所提及的语言特性在C++指最新的C++11标 ...

  6. MyBatis之整合Spring

    MyBatis之整合Spring 整合思路: 1.SqlSessionFactory对象应该放到spring容器中作为单例存在 2.传统dao的开发方式中,应该从spring容器中获得sqlSessi ...

  7. C&plus;&plus;设计模式——单例模式(转)

    问题描述 现在,不管开发一个多大的系统(至少我现在的部门是这样的),都会带一个日志功能:在实际开发过程中,会专门有一个日志模块,负责写日志,由于在系统的任何地方,我们都有可能要调用日志模块中的函数,进 ...

  8. Python知识回顾 —— 面向对象

    博客转载自 http://www.cnblogs.com/wupeiqi/p/4766801.html http://www.cnblogs.com/linhaifeng/articles/62040 ...

  9. 10&period;python面向对象进阶功能

    isinstance(obj,cls)和issubclass(sub,super)(1)isinstance(obj,cls)检查一个对象obj是否是一个类cls的实例(2)issubclass(su ...

  10. 2-glance 部署

    1. mysql 创建数据库和用户 create database glance; grant all privileges on glance.* to 'glance'@'localhost' i ...