标签:scan type mic dom void print mil class cas
其实这道题的思路挺简单的,就是找在第一位置没有出现过并且权值小的那个字母为0.
把a~z按照权值排序,其实难就难在这里,权值很大我们怎么给他排序。
其实可以开个数组来存他们每位数是多少,然后给他们比个大小就好了。
后面排好序就从25开始依次递减
bool cmp(int a, int b) {
for (int i=ans-1; i>=0; i--) {
if (jishu[a][i]!=jishu[b][i]) {
return jishu[a][i]<jishu[b][i];
}
}
return 0;
}
其实就是用一个数组排序来代替那个数的位置
/* gyt Live up to every day */ #include<cstdio> #include<cmath> #include<iostream> #include<algorithm> #include<vector> #include<stack> #include<cstring> #include<queue> #include<set> #include<string> #include<map> #include <time.h> #define PI acos(-1) using namespace std; typedef long long ll; typedef double db; const int maxn = 1e5+10; const ll maxm = 1e7; const ll mod = 1000000007; const int INF = 1<<30; const db eps = 1e-8; int vis[30]; ll num[maxn]; ll sum[maxn]; ll jishu[30][maxn]; ll n,ans,cnt,res,x; char a[maxn]; int ca=1; void initt() { num[0]=1; for (int i=1; i<maxn; i++) { num[i]=num[i-1]*26%mod; } } void init() { ans=0,cnt=-1,res=0,x=25; memset(jishu, 0, sizeof(jishu)); memset(sum, 0, sizeof(sum)); memset(vis, 0, sizeof(vis)); } bool cmp(int a, int b) { for (int i=ans-1; i>=0; i--) { if (jishu[a][i]!=jishu[b][i]) { return jishu[a][i]<jishu[b][i]; } } return 0; } void solve() { initt(); while(scanf("%lld", &n)!=EOF) { init(); for (int i=0; i<n; i++){ scanf("%s", a); ll len=strlen(a); if (len>1) { vis[a[0]-‘a‘]=1; } int xx=0; for (int j=len-1; j>=0; j--) { int v=a[j]-‘a‘; jishu[v][xx]++; sum[v]+=num[xx]; sum[v]%=mod; int cnt=xx; xx++; } ans=max(ans, len); } for(int i=0;i<26;i++){ for(int j=0;j<ans;j++){ jishu[i][j+1]+=jishu[i][j]/26; jishu[i][j]%=26; } while(jishu[i][ans]){ jishu[i][ans+1]+=jishu[i][ans]/26; jishu[i][ans++]%=26; } } for (int i=0; i<26; i++) a[i]=i; sort(a,a+26,cmp);; for (int i=0;i<26;i++) { if (!vis[a[i]]) { cnt=a[i]; break; } } for (int i=25; i>=0; i--) { if (a[i]==cnt) continue; res+=x*sum[a[i]]%mod; res%=mod; x--; } printf("Case #%d: %lld\n", ca++, res); } } int main() { // freopen("in.txt","r",stdin); // freopen("kingdom.in","r",stdin); //freopen("kingdom.out","w",stdout); int t=1; // scanf("%d", &t); while(t--) solve(); }
标签:scan type mic dom void print mil class cas
原文地址:http://www.cnblogs.com/gggyt/p/7239235.html