12-30 Wannafly每日一题 Pretty Song
来源:互联网 发布:矩阵满秩是什么意思 编辑:程序博客网 时间:2024/05/16 07:56
【题目链接】 点击打开链接
【解题方法】
求一个字符串的所有字串的权值和,每个字串的权值为元音字母的个数比上字串的长度将字串转化为01串,那么区间[l,r]的字串的权值为(s[r]-s[l-1])/(r-l+1),枚举长度k,则所有字串的权值和为Sigma(1/k *(s[k]-[s0] + s[k+1]-s[1]+...s[n]-s[n-k]) ) 一式令sum[i]=s[0]+s[1]+s[2]+...+s[i]则一式转化为sum[n]-sum[k-1]-sum[n-k]
【AC代码】
#include <set>#include <map>#include <queue>#include <stack>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef long long LL;const int maxn = 5e5+20;char s[maxn];int a[maxn];LL sum[maxn];int main(){ while(scanf("%s",s+1)!=EOF) { int len = strlen(s+1); for(int i = 1; i <= len; i++){ if(s[i] == 'I' || s[i] == 'E' || s[i] == 'A' || s[i] == 'O' || s[i] == 'U' || s[i] == 'Y'){ a[i] = 1; } else{ a[i] = 0; } } memset(sum, 0, sizeof(sum)); for(int i = 1; i <= len; i++){ a[i] += a[i-1]; sum[i] = sum[i-1] + a[i]; } double ans = 0.0; for(int k = 1; k <= len; k++) { ans = ans + (double)(sum[len] - sum[k - 1] - sum[len - k]) / k*1.0; } printf("%.8f\n", ans); } return 0;}
0 0
- 12-30 Wannafly每日一题 Pretty Song
- Wannafly每日一题 2.17
- Wannafly 每日一题 2016-12-26 KAOS 字典树
- Pretty Song - CodeForces 509 E 想法题
- CF #289 E. Pretty Song
- Codeforces 509E. Pretty Song
- 前缀和 Codeforces509E Pretty Song
- 学英语《每日一歌》之pretty boy
- Codeforces Round #289 (Div. 2, ACM ICPC Rules)E. Pretty Song(数学,想法题,好题)
- CF509E:Pretty Song(规律,前缀和)
- 【水题】Codeforces Round #289 509E Pretty Song
- 数学题 暴力字符串 Codeforces div2 E. Pretty Song
- codeforces 509E Pretty Song [递推]【杂类】
- 每日一佳——Hilbert Space Embeddings of Hidden Markov Models(Le Song,ICML,2010)
- 每日一句2006-12-30
- 每日一题30:拓补排序
- 算法每日一题:12、八个数
- 每日一题(12): poj3276
- C语言之内存图
- 适配器模式(设计模式_19)
- (4.2.7.3)Android PullToRefresh 分析之三、手势响应
- XRecyclerView与轮播图的使用
- 更多赋值运算符和逗号运算符
- 12-30 Wannafly每日一题 Pretty Song
- 操作系统算法 之 银行家算法
- (4.2.7.4) Android PullToRefresh 分析之四、扩展RecyclerView
- 设计心理学的原则和定律之冯·雷斯托夫效应
- SpringBoot使用笔记
- Sunday算法流程与代码
- (4.2.7.5)Android PullToRefresh 分析之五、扩展刷新加载样式
- 后端的基础知识点
- hdu 2639 Bone Collector II