数学规律题,很容易计算的。以初始测试数据3为例。
Str    Y I S V O W E L
--------------------------
Len    1  2 3 4  | 5 6 7  8
Y       +           |           +
I        + +        |       + +
S        
V
O       + + + + | + + + +
W
E       +           |           +
L
首先注意1-4与5-8是对称的(仅长度不同)。长度为2的总数可以在长度为1的总数的基础上累加计算(因为2-len-1的字符若为Vow则各递增1),长度为3的可以在长度为2的基础上累加计算。
故,首先求得cnt[]数组表示从1开始到位置n的Vow字符数目。然后遍历1-len/2的长度,求得结果,若len为奇数,则单独再计算一次(len+1)/2。
其实就是递推规律题目,O(n)时间复杂度。

 /* 509E */
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
using namespace std; #define isVow(ch) (ch=='I'||ch=='E'||ch=='A'||ch=='O'||ch=='U'||ch=='Y') const int maxn = 5e5+;
char s[maxn];
int cnt[maxn]; int main() {
int i, j, k;
int len;
__int64 sum;
int l, r, tmp;
double ans; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif scanf("%s", s+);
memset(cnt, , sizeof(cnt));
for (i=; s[i]; ++i) {
if (isVow(s[i]))
cnt[i] = cnt[i-]+;
else
cnt[i] = cnt[i-];
}
len = i-;
ans = .;
sum = ;
l = ;
r = len;
for (i=, j=len; i<=len/; ++i, --j) {
sum += cnt[r] - cnt[l];
ans += 1.0*sum/i + 1.0*sum/j;
++l;
--r;
}
if (len & ) {
sum += cnt[r] - cnt[l];
ans += 1.0*sum/i;
}
printf("%.7lf\n", ans); #ifndef ONLINE_JUDGE
printf("%d\n", (int)clock());
#endif return ;
}

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

  1. 【CF】438E. The Child and Binary Tree

    http://codeforces.com/contest/438/problem/E 题意:询问每个点权值在 $c_1, c_2, ..., c_m$ 中,总权值和为 $s$ 的二叉树个数.请给出每 ...

  2. 【CF】148D Bag of mice

    http://codeforces.com/problemset/problem/148/D 题意:w个白b个黑,公主和龙轮流取,公主先取,等概率取到一个.当龙取完后,会等概率跳出一只.(0<= ...

  3. 【CF】328 D. Super M

    这种图论题已经变得简单了... /* D */ #include <iostream> #include <string> #include <map> #incl ...

  4. 【CF】323 Div2. D. Once Again...

    挺有意思的一道题目.考虑长度为n的数组,重复n次,可以得到n*n的最长上升子序列.同理,也可以得到n*n的最长下降子序列.因此,把t分成prefix(上升子序列) + cycle(one intege ...

  5. 【CF】7 Beta Round D. Palindrome Degree

    manacher+dp.其实理解manacher就可以解了,大水题,dp就是dp[i]=dp[i>>1]+1如何满足k-palindrome条件. /* 7D */ #include &l ...

  6. 【CF】86 B. Petr#

    误以为是求满足条件的substring总数(解法是KMP分别以Sbeg和Send作为模式串求解满足条件的position,然后O(n^2)或者O(nlgn)求解).后来发现是求set(all vali ...

  7. 【CF】121 Div.1 C. Fools and Roads

    题意是给定一棵树.同时,给定如下k个查询: 给出任意两点u,v,对u到v的路径所经过的边进行加计数. k个查询后,分别输出各边的计数之和. 思路利用LCA,对cnt[u]++, cnt[v]++,并对 ...

  8. 【CF】310 Div.1 C. Case of Chocolate

    线段树的简单题目,做一个离散化,O(lgn)可以找到id.RE了一晚上,额,后来找到了原因. /* 555C */ #include <iostream> #include <str ...

  9. 【CF】110 Div.1 B. Suspects

    这题目乍眼一看还以为是2-sat.其实很水的,O(n)就解了.枚举每个人,假设其作为凶手.观察是否满足条件.然后再对满足的数目分类讨论,进行求解. /* 156B */ #include <io ...

随机推荐

  1. angularjs-yeoman环境配置

    yum install npm -y npm install -g grunt-cli bower yo generator-karma-require generator-angular-requi ...

  2. JS如何封装一些列方法为一个对象的操作,然后集中管理这些操作,方便修改和调用

    var Api = { ajax:{ // 添加项目 旧! add_project : function(pro_name, html, css, js,callback) { $.post(&quo ...

  3. ActionLink 的一些小问题

    近日为群友解答问题时遇到一个问题 由于自己以前确实没碰到过 特此记录一下 起因是群友想要用htmlhelper实现这样一个效果 <a href="我是链接" class=&q ...

  4. asp.net之动态页面和静态页面的区别

    asp.net之动态页面和静态页面的区别 当我开始接触web开发的时候,首先学到的是html.css.js这一类网页语言,通过布局可以搭建出一个静态网站,效果也跟我们上网时经常看到的一些网站一样了.于 ...

  5. Context是什么,怎么用

    一.Context是什么 开始学安卓的时候发现经常有context,但是都不知道为什么,什么时候需要它. 官方文档概述:关于应用程序环境的全局信息的接口.这是一个抽象类,它的实现是由安卓系统提供的.它 ...

  6. Could not parse mapping document from resource cn/spt/model/Student.hbm.xml

    初始hibernate, 写第一个程序 helloworld的错误: Exception in thread "main" org.hibernate.InvalidMapping ...

  7. C# - linq查询现有的DataTable

    可以通过linq对现有的DataTable进行查询,并将结果拷贝至新的DataTable中例如: // Query the SalesOrderHeader table for orders plac ...

  8. iBATIS缓存cacheModel属性浅析

    iBATIS缓存cacheModel属性的应用使得在Mapped Statement中缓存常用的数据,那么本文将会给你介绍iBATIS缓存cacheModel属性的信息. AD:2013云计算架构师峰 ...

  9. jquery 过滤器

    1.基本选择器 基本选择器是JQuery中最常用的选择器,也是最简单的选择器,它通过元素id.class 和标签名来查找DOM元素.这个非常重要,下面的内容都是以此为基础,逐级提高的. 1).“$(“ ...

  10. php hook example

    http://www.thinkphp.cn/code/337.html http://blog.micxp.com/index.php/archives/63/