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

【题意】



让你计算一个字符串的所有子串里面元音字母出现的频率的和;

【题解】



先处理出前缀和->pre[i]->前i个字母里面元音字母的个数;

设ans[i]

表示长度为i的子串出现的元音字母的个数(重复的也要算进去);

注意到以下事实

长度为2的子串中第一个和最后一个字母出现的次数为1,其他为2;

长度为3的子串中第一个和最后一个字母出现的次数为1,第二个和最后第二个字母出现的次数为2,其他为3;

。。。

则能写出递推式

ans[i]=ans[i-1]+pre[n-i+1]-pre[i-1];

然后输出∑ans[i]/i就好



【Number Of WA】



0



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) cin >> x
#define pri(x) cout << x
#define ms(x,y) memset(x,y,sizeof x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 5e5+100; char s[N];
int pre[N],n;
map<char,int> dic;
double ans[N],temp=0; int main()
{
//freopen("F:\\rush.txt","r",stdin);
ios::sync_with_stdio(false);
dic['I']=dic['E']=dic['A']=dic['O']=dic['U']=dic['Y'] = 1;
rei((s+1));
n = strlen(s+1);
rep1(i,1,n)
if (dic[s[i]])
pre[i] = pre[i-1]+1;
else
pre[i] = pre[i-1];
ans[1] = pre[n];
rep1(i,2,n)
ans[i] = ans[i-1]+pre[n-i+1]-pre[i-1];
rep1(i,1,n)
{
double j = i;
temp+=ans[i]/j;
}
printf("%.10f\n",temp);
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

【codeforces 509E】Pretty Song的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  3. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  4. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  5. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  6. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  7. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  8. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

  9. 【codeforces 515D】Drazil and Tiles

    [题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...

随机推荐

  1. 【总结】设备树对platform平台设备驱动带来的变化(史上最强分析)【转】

    本文转载自:http://blog.csdn.net/fengyuwuzu0519/article/details/74375086 版权声明:本文为博主原创文章,转载请注明http://blog.c ...

  2. 使用EL表达式正确情况下报错:javax.servlet.jsp cannot be resolved to a type

    这个错误可能是服务器自带的servlet库未导入的原因.右键项目属性,转到Targeted Runtimes,选择一个服务器,例如Tomcat,单击应用,可能就可以解决.

  3. etcd磁盘清理步骤

    etcd默认的空间配额限制为2G,超出空间配额限制就会影响服务,所以需要定期清理 以下是etcd磁盘清理的步骤: 1. 显示空间配额: ETCDCTL_API=3 etcdctl --endpoint ...

  4. PCB 规则引擎之脚本语言JavaScript应用评测

    世界上没有好做的软件,觉得好做,只是你的系统简单而已,而不是哪个行业简单,特别像我们PCB制造企业务逻辑的很复杂的,仅仅靠决策树中的每个节点布置决策逻辑是不能满足要求的,所以我们在制作PCB规则引擎必 ...

  5. Kindergarten Election

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3715 题意:有N个孩子投票选举leader,不能自己选自己.Sheldon ...

  6. $P2126 Mzc家中的男家丁$

    problem #ifdef Dubug #endif #include <bits/stdc++.h> using namespace std; typedef long long LL ...

  7. JavaScript--输出内容(document.write)

    document.write() 可用于直接向 HTML 输出流写内容.简单的说就是直接在网页中输出内容. 第一种:输出内容用“”括起,直接输出""号内的内容. <scrip ...

  8. ACM_整数反转

    整数反转 Time Limit: 2000/1000ms (Java/Others) Problem Description: 给定一个32位int型的整数,把这个整数反着输出,如123,输出321. ...

  9. Jquery 实现列表的显示和隐藏

    本人github源码下载地址:https://github.com/liuyanpeng521/ListChange.git

  10. node 第三方包学习

    时间格式化 moment var moment = require('moment'); moment().format();