读书人

Codeforces Round #129 (Div. 二)

发布时间: 2012-08-15 16:57:17 作者: rapoo

Codeforces Round #129 (Div. 2)

转载请注明出处,谢谢 http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove

没想到提交的4题都过了, 第一次,rate也涨了,终于紫了。

总结:小错误太多

A:问距离最近的城市是不是唯一。唯一则输出标号,就是个排序

#include<iostream>#include<cstdio>#include<cstring>#define LD long double#define LL __int64#define M 200005int n;char str1[M],str2[M];int main(){while(scanf("%d%s%s",&n,str1,str2)!=EOF){LD ans=0;for(int ch='A';ch<='Z';ch++){int j=n-1;LD p=0;for(int i=n-1;i>=0;i--){if(str1[i]==ch){while(j>i){if(str2[j]==ch)p+=n-j;j--;}ans+=p*(i+1);}}j=n-1;p=0;for(int i=n-1;i>=0;i--){if(str2[i]==ch){while(j>=i){if(str1[j]==ch)p+=n-j;j--;}ans+=p*(i+1);}}}printf("%.10f\n",(LD)ans*6/((LD)n*(n+1)*(2*n+1)));}return 0;}


读书人网 >编程

热点推荐