「CF509E」Pretty Song
题解
将序列看成01串,元音为1
要算∑ (sum(j)-sum(i+1))/(j-i+1)
发现枚举分母后,对于sum再维护前缀和sum2,就能每次O1时间计算对答案贡献
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<set> #include<ctime> #include<vector> #include<queue> #include<algorithm> #include<map> #include<cmath> #define mod 30031 #define inf 1000000000 #define rad 100000000 #define pa pair<int,int> #define ll long long using namespace std; int read() { int 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; } char ch[6]={'A','E','I','O','U','Y'},a[500005]; int n; ll s[500005],s2[500005]; double ans; bool jud(char c) { for(int i=0;i<6;i++)if(ch[i]==c)return 1; return 0; } int main() { scanf("%s",a+1); n=strlen(a+1); for(int i=1;i<=n;i++) s[i]=s[i-1]+jud(a[i]); for(int i=1;i<=n;i++) s2[i]=s2[i-1]+s[i]; for(int i=1;i<=n;i++) { ll tmp=0; tmp+=s2[n]-s2[i-1]; tmp-=s2[n-i]; ans+=(double)tmp/i; } printf("%.8lf",ans); return 0; } |
Subscribe