JZOJ 2197. 【中山市选2010】三核苷酸
题目
2197. 【中山市选2010】三核苷酸(tri.pas/.cpp)
(File IO): input:tri.in output:tri.out
Time Limits: 1000 ms Memory Limits: 256000 KB Detailed Limits
Source / Author: 中山市选2010 tri
分析
代码
1 #include<vector> 2 #include<stdio.h> 3 #include<string.h> 4 #include<algorithm> 5 using namespace std; 6 vector<long long> c[64]; 7 int n,T,d[128]; char t[100010]; 8 long long s[100010],s2[100010],S,S2,N; 9 void fun(){ 10 scanf("%s",t+1); 11 n=strlen(t+1); 12 S=S2=N=0; 13 for(int i=3;i<=n;++i) 14 c[d[t[i]]+d[t[i-1]]*4+d[t[i-2]]*16].push_back(i); 15 for(int i=0;i<64;++i) 16 if(c[i].size()>1){ 17 N+=c[i].size()*(c[i].size()-1)>>1; 18 for(int j=0,z=c[i].size();j<z;++j) 19 s[j+1]=s[j]+c[i][j],s2[j+1]=s2[j]+c[i][j]*c[i][j]; 20 for(int j=1,z=c[i].size();j<z;++j) 21 S+=c[i][j]*j-s[j],S2+=c[i][j]*c[i][j]*j+s2[j]-2*c[i][j]*s[j]; 22 } 23 if(N==0) puts("0.000000"); 24 else printf("%.6lf\n",-(double)S/N*S/N+(double)S2/N); 25 } 26 int main(){ 27 freopen("tri.in","r",stdin); 28 freopen("tri.out","w",stdout); 29 d['A']=0; d['G']=1; d['C']=2; d['T']=3; 30 for(scanf("%d",&T);T--;fun()) 31 for(int i=0;i<64;++i) c[i].clear(); 32 }
为何要逼自己长大,去闯不该闯的荒唐