2017 Multi-University Training Contest 1 hdu 6034
思路:
AC代码:
#include "iostream" #include "string.h" #include "stack" #include "queue" #include "string" #include "vector" #include "set" #include "map" #include "algorithm" #include "stdio.h" #include "math.h" #define ll long long #define bug(x) cout<<x<<" "<<"UUUUU"<<endl; #define mem(a) memset(a,0,sizeof(a)) #define mp(x,y) make_pair(x,y) #define pb(x) push_back(x) using namespace std; const long long INF = 1e18+1LL; const int inf = 1e9+1e8; const int N=1e5+100; const ll mod=1e9+7; ///1002 char s[N]; int lm,n; ll mi[N]; map<char,int> M; struct Node{ int a[N],id; bool friend operator< (Node x, Node y){ for(int i=lm; i>=1; --i){ if(x.a[i]!=y.a[i]) return x.a[i]>y.a[i]; } return 0; } }; Node bit[26]; int main(){ int t=1; for(ll i=0,base=1;i<N;i++,base=(base*26)%mod) mi[i] = base; //ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); while(~scanf("%d", &n)){ M.clear(),lm=0; for(int i=0; i<=25; ++i) bit[i].id=200; while(n--){ scanf("%s", s); int ls=strlen(s),b=ls; if(ls>1) M[s[0]-'a']=1; lm=max(lm,ls); for(int i=0; i<ls; ++i){ bit[s[i]-'a'].a[b-i]++; bit[s[i]-'a'].id=s[i]-'a'; } } for(int i=0; i<=25; ++i){ for(int j=1;j<=N-1; ++j){ if(bit[i].a[j]>25){ bit[i].a[j+1]+=bit[i].a[j]/26; bit[i].a[j]%=26; lm=max(lm,j+1); } } } sort(bit,bit+26); ll r=26; int p=-1; for(int i=0; i<=25; ++i){ if(bit[i].id==200) break; --r; }//for(int i=0; i<=25; ++i) cout<<mp[i]<<" "; if(r==0){ for(int i=25; i>=0; --i){ if(!M[bit[i].id]){ p=bit[i].id; break; } } } //for(int i=0; i<=25; ++i) cout<<mp[i]<<" "; ll ans=0,f; r=26; for(int i=0; i<=25; ++i){ if(bit[i].id==p) f=0; else f=--r; for(int j=1; j<=lm; ++j){ ans+=(((f*bit[i].a[j])%mod)*mi[j-1])%mod; bit[i].a[j]=0; } } printf("Case #%d: %lld\n", t++, (ans+mod)%mod); } return 0; }