cf509E Pretty Song
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 strings, 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.
The input contains a single string s (1 ≤ |s| ≤ 5·105) — the title of the song.
Print the prettiness of the song with the absolute or relative error of at most 10 - 6.
IEAIAIO
28.0000000
BYOB
5.8333333
YISVOWEL
17.0500000
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.
题意是把字符串变成01串,元音字母是1其他是0,然后一个子串[l,r]对答案的贡献是(s[r]-s[l-1])/(r-l+1),求答案
枚举分母k,那么答案就是Σ(s[k]-s[0]+s[k+1]-s[1]+...+s[n]-s[n-k+1])/k
令t[]是s的前缀和,那么答案就是Σ(t[n]-t[n-k+1]-t[k])/k
O(n)搞定了
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7fffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n;
char ch[1000010];
int a[1000010];
LL s[1000010],t[1000010];
double ans;
int main()
{
scanf("%s",ch+1);
n=strlen(ch+1);
for(int i=1;i<=n;i++)
a[i]=ch[i]=='A'||ch[i]=='E'||ch[i]=='I'||ch[i]=='O'||ch[i]=='U'||ch[i]=='Y';
for(int i=1;i<=n;i++)
{
s[i]=s[i-1]+a[i];
t[i]=t[i-1]+s[i];
}
for(int i=1;i<=n;i++)
{
ans+=(double)(t[n]-t[i-1]-t[n-i])/(i+0.0);
}
printf("%.6lf\n",ans);
}
cf509E Pretty Song的更多相关文章
随机推荐
- (五)unity4.6Ugui中文教程文档-------概要-UGUI Interaction Components
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDAxOTcxNw==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- Android ArrayAdapter MultiAutoCompleteTextView
MultiAutoCompleteTextView 继承自AutoCompleteTextView,它和AutoCompleteTextView不同的就是能处理多个输入字段,如发送短信界面的联系人列表 ...
- android不自动弹出虚拟键盘
如果是Activity的话 在 Manifest.xml 相应的 Activity 里添加 android:windowSoftInputMode="adjustPan|stateHidde ...
- Linux下查看所有用户(shell脚本获取)
在Linux系统中,使用者账号管理最重要的两个文件是/etc/password和/etc/shadow.在/etc/password文件中,每一行都代表一个账号,但是有很多账号是系统账号.比如:b ...
- webform 复杂点的服务器控件
1 , dropdownlist: 下拉框 属性items 列表集合, 里面的每一个元素是一个 listitem . 联动的时候注意要 设置属性 .Autopostback 为ture: 注注 ...
- PHP编写的SVN类
<?php /** * SVN 外部命令 类 * * @author rubekid * * @todo comment need addslashes for svn commit * */ ...
- java获取字符串格式日期向前或向后n天的日期
private void setTilteMessage(){ BaseDao dao = new BaseDao(); String titleData = da ...
- CSS 样式属性锦集
ul#nav > Li 只有一个大于号,是指应用了#nav这个ID的下一级元素的儿子辈Li 元素定义的内容符合这个CSS代码定义的样式,但是孙子辈Li元素定义的内容就不符合这个CSS代码样式了, ...
- oracle存储过程调试方法
PL/SQL中为我们提供了[调试存储过程]的功能,可以帮助你完成存储过程的预编译与测试. 点击要调试的存储过程,右键选择TEST 如果需要查看变量,当然调试都需要.在右键菜单中选择Add debug ...
- php中bindValue的批量提交sql语句
php预编译sql语句,可以批量提交sql,也可以实现防注入 <?php $dsn='mysql:host=127.0.0.1;port=3306;dbname=bisai'; $usernam ...