Codeforces Round #289 (Div. 2, ACM ICPC Rules) E. Pretty Song

来源:互联网 发布:剑网三捏脸数据萝莉 编辑:程序博客网 时间:2024/05/16 00:57

考虑每一位对答案的影响,然后三种情况分类讨论。。。

#include <iostream>#include <queue>#include <stack>#include <map>#include <set>#include <bitset>#include <cstdio>#include <algorithm>#include <cstring>#include <climits>#include <cstdlib>#include <cmath>#include <time.h>#define maxn 500005#define maxm 200005#define eps 1e-7#define mod 1000000007#define INF 0x3f3f3f3f#define PI (acos(-1.0))#define lowbit(x) (x&(-x))#define mp make_pair#define ls o<<1#define rs o<<1 | 1#define lson o<<1, L, mid #define rson o<<1 | 1, mid+1, R#define pii pair<int, int>#pragma comment(linker, "/STACK:16777216")typedef long long LL;typedef unsigned long long ULL;using namespace std;LL qpow(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base;base=base*base;b/=2;}return res;}LL powmod(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base%mod;base=base*base%mod;b/=2;}return res;}//headchar s[maxn];double sum1[maxn];double sum2[maxn];int n;void read(){scanf("%s", s + 1);n = strlen(s + 1);}bool check(char c){if(c == 'A') return true;if(c == 'E') return true;if(c == 'I') return true;if(c == 'O') return true;if(c == 'U') return true;if(c == 'Y') return true;return false;}void work(){double ans = 0;for(int i = 1; i <= n; i++) sum1[i] = 1.0 / i;for(int i = 1; i <= n; i++) sum1[i] += sum1[i-1];for(int i = 1; i <= n; i++) sum2[i] = 1.0 * (n - i + 1) / i;for(int i = n; i >= 1; i--) sum2[i] += sum2[i+1];for(int i = 1; i <= n; i++) if(check(s[i])) {int a = i - 1, b = n - i;if(a > b) swap(a, b);ans += a + 1;ans += (sum1[b+1] - sum1[a+1]) * (a + 1);ans += sum2[b+2];}printf("%.9f\n", ans);}int main(){read();work();return 0;}


0 0
原创粉丝点击