hdu 6034 Balala Power!
Balala Power!
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 3555 Accepted Submission(s): 844

Talented Mr.Tang has n strings consisting of only lower case characters. He wants to charge them with Balala Power (he could change each character ranged from a to z into each number ranged from 0 to 25, but each two different characters should not be changed into the same number) so that he could calculate the sum of these strings as integers in base 26 hilariously.
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 109+7.
For each test case, the first line contains one positive integers n, the number of strings. (1≤n≤100000)
Each of the next n lines contains a string si consisting of only lower case letters. (1≤|si|≤100000,∑|si|≤106)
#include <iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<bits/stdc++.h> using namespace std;
const long long mod=1e9+;
struct node
{
int id;
double k;
}a[];
int b[];
long long num[][];
bool vis[];
char ch[];
int n,maxlen; bool cmp(node a,node b)
{
return a.k>b.k;
}
int main()
{
int cas=;
while(~scanf("%d",&n))
{
maxlen=;
memset(num,,sizeof(num));
memset(vis,,sizeof(vis));
for(;n>;n--)
{
scanf("%s",&ch);
int l=strlen(ch);
maxlen=max(maxlen,l);
if (l>) vis[ch[]-'a']=;
for(int i=;i<l;i++)
num[ch[i]-'a'][l-i-]++;
} for(int i=;i<;i++)
{
a[i].id=i; a[i].k=;
for(int j=;j<maxlen;j++)
a[i].k=a[i].k/+num[i][j];
} sort(a,a+,cmp); for(int i=;i>=;i--)
{
if (vis[a[i].id]) continue;
else
{
int cnt=;
for(int j=;j<;j++)
if (j!=i) b[a[j].id]=cnt--;
else b[a[j].id]=;
break;
}
} long long ans=;
for(int i=;i<;i++)
{
long long ret=;
for(int j=;j<maxlen;j++)
{
ans=(ans+num[i][j]*ret*b[i])%mod;
ret=(ret*)%mod;
}
}
printf("Case #%d: %lld\n",++cas,ans);
}
return ;
}
hdu 6034 Balala Power!的更多相关文章
- HDU 6034 - Balala Power! | 2017 Multi-University Training Contest 1
/* HDU 6034 - Balala Power! [ 大数进位,贪心 ] 题意: 给一组字符串(小写英文字母),将上面的字符串考虑成26进制数,每个字母分配一个权值,问这组数字加起来的和最大是多 ...
- 2017 Multi-University Training Contest - Team 1 1002&&HDU 6034 Balala Power!【字符串,贪心+排序】
Balala Power! Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- HDU 6034 Balala Power!(贪心+排序)
Balala Power! Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 2017ACM暑期多校联合训练 - Team 1 1002 HDU 6034 Balala Power! (字符串处理)
题目链接 Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He ...
- HDU 6034 Balala Power!【排序/进制思维】
Balala Power![排序/进制思维] Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java ...
- HDU 6034 Balala Power! —— Multi-University Training 1
Talented Mr.Tang has nn strings consisting of only lower case characters. He wants to charge them wi ...
- HDU 6034 Balala Power! (贪心+坑题)
题意:给定一个 n 个字符串,然后问你怎么给 a-z赋值0-25,使得给定的字符串看成26进制得到的和最大,并且不能出现前导0. 析:一个很恶心的题目,细节有点多,首先是思路,给定个字符一个权值,然后 ...
- 6034 Balala Power! (17多校)
题目大意:给出的字符串,每个字符建立一种与0-25的对应关系.然后每个字符串看成是一个26进制的数.问能获得的数的总和的最大值.(最后对1e9+7取模). 题目思考:把每个字符的贡献值看做一个26进制 ...
- hdu 6034 B - Balala Power! 贪心
B - Balala Power! 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6034 题面描述 Talented Mr.Tang has n st ...
随机推荐
- Linux 磁盘
一台物理服务器通常有好几块磁盘(/dev/sda,/dev/sdb),每个磁盘上都可以进行分区(例如对sda进行分区操作:fdisk /dev/sda,可以将sda分成sda1,sda2,sda5等分 ...
- message from server: "Host '192.168.6.68' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts
系统或者程序连接数据报错 null, message from server: "Host '192.168.6.68' is blocked because of many connect ...
- clientWidth offsetWidth scrollWidth
网页可见区域宽: document.body.clientWidth;网页可见区域高: document.body.clientHeight;网页可见区域宽: document.body.offset ...
- js 代码执行时间
<html> <head> </script> <script> var sTime=new Date().getTime(); alert(&qu ...
- JAVA国际化输出日期格式
1.建议控制台程序 使用 IntelliJ IDEA 创建 MAVEN项目, 不选别的选项,则为控制台程序. (其它方式创建的控制台程序可能编译不过) 2.源码如下: import java.tim ...
- Android Studio开发学习 - 1. 添加Activity
1. 项目上点右键,New -> Activity -> Blank Activity 这将生成Activity的 Layout.Class .和相关的配置信息(在AndroidManif ...
- 为什么说git比svn好
http://blog.jobbole.com/20069/ git的权限控制,可以借助第三方的工具来实现 也快成使用git的子模块 http://www.cnblogs.com/aga-j/arch ...
- 2017 beijing icpc A - Euler theorem
2017-09-22 21:59:43 writer:pprp HazelFan is given two positive integers a,ba,b, and he wants to calc ...
- The SO_REUSEPORT socket option
One of the features merged in the 3.9 development cycle was TCP and UDP support for the SO_REUSEPORT ...
- 关于Eclipse SVN 分支 与主干 小结
SVN建立分支和合并代码 https://blog.csdn.net/luofeixiongsix/article/details/52052631 SVN创建指定版本号的分支 https://blo ...