标签:problem stream diff frame note sub bre charge different
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 3555 Accepted Submission(s): 844
#include <iostream> #include<cstdio> #include<cstring> #include<queue> #include<bits/stdc++.h> using namespace std; const long long mod=1e9+7; struct node { int id; double k; }a[30]; int b[30]; long long num[30][100005]; bool vis[30]; char ch[100005]; int n,maxlen; bool cmp(node a,node b) { return a.k>b.k; } int main() { int cas=0; while(~scanf("%d",&n)) { maxlen=0; memset(num,0,sizeof(num)); memset(vis,0,sizeof(vis)); for(;n>0;n--) { scanf("%s",&ch); int l=strlen(ch); maxlen=max(maxlen,l); if (l>1) vis[ch[0]-‘a‘]=1; for(int i=0;i<l;i++) num[ch[i]-‘a‘][l-i-1]++; } for(int i=0;i<26;i++) { a[i].id=i; a[i].k=0; for(int j=0;j<maxlen;j++) a[i].k=a[i].k/26+num[i][j]; } sort(a,a+26,cmp); for(int i=25;i>=0;i--) { if (vis[a[i].id]) continue; else { int cnt=25; for(int j=0;j<26;j++) if (j!=i) b[a[j].id]=cnt--; else b[a[j].id]=0; break; } } long long ans=0; for(int i=0;i<26;i++) { long long ret=1; for(int j=0;j<maxlen;j++) { ans=(ans+num[i][j]*ret*b[i])%mod; ret=(ret*26)%mod; } } printf("Case #%d: %lld\n",++cas,ans); } return 0; }
标签:problem stream diff frame note sub bre charge different
原文地址:http://www.cnblogs.com/stepping/p/7240175.html