HDU6034 Balala Power!(思路+大数)
来源:互联网 发布:韩服数据 编辑:程序博客网 时间:2024/05/22 15:12
Balala Power!
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2340 Accepted Submission(s): 457
Problem Description
Talented Mr.Tang has
Mr.Tang wants you to maximize the summation. Notice that no string in this problem could have leading zeros except for string "0". It is guaranteed that at least one character does not appear at the beginning of any string.
The summation may be quite large, so you should output it in modulo
Input
The input contains multiple test cases.
For each test case, the first line contains one positive integersn , the number of strings. (1≤n≤100000)
Each of the nextn lines contains a string si consisting of only lower case letters. (1≤|si|≤100000,∑|si|≤106)
For each test case, the first line contains one positive integers
Each of the next
Output
For each test case, output "Case #x : y " in one line (without quotes), where x indicates the case number starting from 1 and y denotes the answer of corresponding case.
Sample Input
1a2aabb3abaabc
Sample Output
Case #1: 25Case #2: 1323Case #3: 18221
题意:给出 n个字符串,字符包括 a~z,分别给它们赋值 0~25,使得这些串表达成26进制时的和最大
求出每个位置每个字母的个数,倒着存,此时就有大数的思想,相当于一个26进制的大数,首先要对获得的大数进位,满26进1
然后比较每个字母的贡献,重载<,用sort对获得的大数排序,依次赋值
最后考虑前导0的情况,找到第一个最小的不能为前导0的位置,把该位置变为0,循环左移即可
#include<stdio.h>#include<string.h>#include<iostream>#include<string>#include<algorithm>#define mem(a,b) memset(a,b,sizeof(a))using namespace std;typedef long long ll;const int N=100100;const int MOD=1e9+7;const int M=30;struct node{ int num[N]; int id; bool operator < (const node&a)const { for(int i=100000;i>=0;i--) { if(num[i]!=a.num[i]) return num[i]>a.num[i]; } return 0; }}e[M];bool vis[M];ll num[M],re[N];string s[N];int main(){ ios::sync_with_stdio(false); re[0]=1; for(int i=1;i<N;i++) { re[i]=re[i-1]*26; re[i]%=MOD; } int n,q=0; while(cin>>n) { for(int i=0;i<26;i++) { for(int j=0;j<=100000;j++) e[i].num[j]=0; e[i].id=i; vis[i]=0; } for(int i=0;i<n;i++) { cin>>s[i]; int lenn=s[i].length(); for(int j=0,k=lenn-1;j<lenn;j++,k--) { int t=s[i][k]-'a'; e[t].num[j]++; } if(lenn>1)vis[s[i][0]-'a']=1; } for(int i=0;i<26;i++) { for(int j=0;j<=100000;j++) { e[i].num[j+1]+=e[i].num[j]/26; e[i].num[j]%=26; } } sort(e,e+26); for(int i=25;i>=0;i--) { num[e[25-i].id]=i; } int t=25; while(vis[e[t].id]&&t) { swap(num[e[t].id],num[e[t-1].id]); t--; } ll ans=0; for(int i=0;i<n;i++) { int len=s[i].length(); for(int j=0;j<len;j++) { ans=(ans+num[s[i][j]-'a']*re[len-1-j]%MOD)%MOD; } } cout<<"Case #"<<++q<<": "<<ans<<endl; }}
阅读全文
0 0
- HDU6034 Balala Power!(思路+大数)
- HDU6034 Balala Power! [贪心]
- HDU6034-Balala Power! 贪心
- hdu6034 Balala Power! 贪心
- HDU6034 Balala Power! (字符串)
- HDU6034-Balala Power!
- HDU6034 Balala Power!【贪心】
- hdu6034(Balala Power!)
- HDU6034-Balala Power-模拟
- HDU6034-Balala Power!
- hdu6034 Balala Power!
- hdu6034--Balala Power!
- hdu6034(Balala Power!)
- HDU6034 Balala Power!
- 【HDU6034】Balala Power!
- hdu6034-贪心&进制-2017多校1-Balala Power!
- HDU 6034 Balala Power!(大数进制)
- HDU 6034 Balala Power! 【模拟】【大数高精度】
- 解题报告:HDU_6040 Hints of sd0061 STL::nth_element
- superDiamond例子
- Tools 命名空间的使用与 Support Library Annotations 介绍
- sql count(id)返回long型数据
- iOS11新特性,如何适配iOS11
- HDU6034 Balala Power!(思路+大数)
- android活动
- 剑指Offer:复杂链表的复制
- 一行数据自适应不换行
- Nginx 平滑升级
- 用python读取xml文件的写法举例
- Tomcat+Nginx+Keepalived+Redis集群
- Lua中的正则表达式
- LA 4987 n个人要到m个避难所 每个避难所最少一人 求所用最短距离