#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
const int N=100005;
#define ll long long
char c[N];
int T,n,i,a[N],b[N];
ll s[505],sum[505],cnt[505],s1[505],s2[505],S,ans,Ans;
double fans;
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%s",c+1);
n=strlen(c+1);
for(i=111;i<=444;i++)
s[i]=sum[i]=s1[i]=s2[i]=cnt[i]=0;
for(i=1;i<=n;i++)
{
if(c[i]=='A') a[i]=1;else
if(c[i]=='G') a[i]=2;else
if(c[i]=='C') a[i]=3;else
a[i]=4;
}
for(i=1;i<=n-2;i++)
b[i]=a[i]*100+a[i+1]*10+a[i+2];
for(i=1;i<=n-2;i++)
{
s[b[i]]+=cnt[b[i]]*i*i+s1[b[i]]-s2[b[i]]*i*2;
sum[b[i]]+=cnt[b[i]]*i-s2[b[i]];
s1[b[i]]+=(ll)i*i;
s2[b[i]]+=i;
cnt[b[i]]++;
}
ans=Ans=S=0;
for(i=111;i<=444;i++)
ans+=s[i],Ans+=sum[i],S+=cnt[i]*(cnt[i]-1)/2;
if(S==0) fans=0;else fans=1.0*ans/S-(1.0*Ans/S)*(1.0*Ans/S);
printf("%.6f\n",fans);
}
return 0;
}
12468:[中山市选2010]三核苷酸
最新推荐文章于 2024-09-03 20:45:39 发布