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的更多相关文章
随机推荐
- 解决git提交问题error: The requested URL returned error: 403 Forbidden while accessing
git提交代码时,出现这个错误"error: The requested URL returned error: 403 Forbidden while accessing https&qu ...
- 怎样绕过oracle listener 监听的password设置
怎样绕过oracle 监听的password设置: 1.找到监听进程pid ,并将它kill 掉 ps -ef|grep tns [oracle@lixora admin]$ ps -ef|gr ...
- 开发中可能会用到的几个 jQuery 小提示和技巧 (转)
转自:http://www.cnblogs.com/lhb25/p/useful-jquery-tips-and-tricks.html 今天,我们将分享一些很有用的技巧和窍门给 jQuery 开发人 ...
- nyoj 756 重建二叉树
重建二叉树主要是给你一颗二叉树的前序遍历的结果和中序遍历的结果或者后序遍历的结果或者中序遍历的结果,让你求出其中的后序遍历的结果或者前序遍历的结果,这里知道其中的两个就能求出第三个,但是知道的两个必须 ...
- 10、第十节课jq420151012
1.点击交替显示隐藏功能 点击交替执行的:fadeToggle(1000) , slideToggle() , toggle(1000); 2.点击单独执行 单独显示/隐藏:sho ...
- JQuery 操作基本控件
根据控件的样式class获取控件 $(".className")...... //className代表的就是控件的样式 根据控件的ID获取控件 $(" ...
- 禁止Windows远程桌面拷贝文件
通过组策略,我们可以解决以上问题,开始菜单运行输入gpedit.msc,进入“计算机配置”项,按顺序进入“管理模板”.“windows组件”.“终端服务”.“客户端/服务器数据重定向”.在详细描述栏中 ...
- sql语法图
- [置顶] 让你的Android应用与外部元素互动起来
传送门 ☞ 轮子的专栏 ☞ 转载请注明 ☞ http://blog.csdn.net/leverage_1229 一个Android应用程序通常有几个activities.每个act显示一个用户接口允 ...
- IntelliJ IDEA 12 创建Web项目 教程 超详细版
IntelliJ IDEA 12 新版本发布 第一时间去官网看了下 黑色的主题 很给力 大体使用了下 对于一开始就是用eclipse的童鞋们 估计很难从eclipse中走出来 当然 我也很艰难的走 ...