HDU 6034 贪心
Balala Power!
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 3757 Accepted Submission(s): 907

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)
a
//进位和去前导零!!!;统计每个字符在某一位置出现的次数(共1e5个位置),然后贪心一定是贡献值最大的
//用25,把统计出来的数组按照高位出现次数大的排序(可以按照数组排序),然后算就行了。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1e9+;
const int maxl=;
int pre[];
ll f[maxl];
struct Lu{
int id,ss[maxl];
ll v;
bool operator < (const Lu &p)const{
for(int i=maxl-;i>=;i--){
if(ss[i]>p.ss[i]) return ;
else if(ss[i]<p.ss[i]) return ;
}
}
}L[];
void init(){
f[]=;
for(int i=;i<maxl;i++){
f[i]=f[i-]*%mod;
}
}
int main()
{
init();
int cas=,n;
char str[maxl];
while(scanf("%d",&n)==){
memset(pre,,sizeof(pre));
memset(L,,sizeof(L));
for(int i=;i<n;i++){
scanf("%s",str);
int len=strlen(str)-;
if(len!=)
pre[str[]-'a']=;
for(int j=len;j>=;j--){
int id=str[j]-'a';
L[id].ss[len-j]++;
}
}
for(int i=;i<;i++){
L[i].id=i;
for(int j=;j<maxl-;j++){
if(L[i].ss[j]>=){
L[i].ss[j+]+=L[i].ss[j]/;
L[i].ss[j]%=;
}
}
}
sort(L,L+);
for(int i=;i<;i++)
L[i].v=-i;
if(pre[L[].id]){ //去前导零时可不是直接交换
for(int i=;i>=;i--){
if(!pre[L[i].id]){
for(int j=;j>i;j--)
L[j].v=L[j-].v;
L[i].v=;
break;
}
}
}
ll sum=;
for(int i=;i<;i++){
for(int j=maxl-;j>=;j--){
sum+=L[i].v*f[j]*L[i].ss[j]%mod;
sum%=mod;
}
}
printf("Case #%d: %lld\n",++cas,sum);
}
return ;
}
HDU 6034 贪心的更多相关文章
- hdu 6034 贪心模拟 好坑
关键在排序!!! 数组间的排序会超时,所以需要把一个数组映射成一个数字,就可以了 #include <bits/stdc++.h> using namespace std; typedef ...
- HDU 6034 Balala Power!(贪心+排序)
Balala Power! Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 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 B - Balala Power! 贪心
B - Balala Power! 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6034 题面描述 Talented Mr.Tang has n st ...
- HDU 6034 Balala Power! (贪心+坑题)
题意:给定一个 n 个字符串,然后问你怎么给 a-z赋值0-25,使得给定的字符串看成26进制得到的和最大,并且不能出现前导0. 析:一个很恶心的题目,细节有点多,首先是思路,给定个字符一个权值,然后 ...
- Hdu 5289-Assignment 贪心,ST表
题目: http://acm.hdu.edu.cn/showproblem.php?pid=5289 Assignment Time Limit: 4000/2000 MS (Java/Others) ...
- hdu 4803 贪心/思维题
http://acm.hdu.edu.cn/showproblem.php?pid=4803 话说C++还卡精度么? G++ AC C++ WA 我自己的贪心策略错了 -- 就是尽量下键,然后上 ...
- hdu 1735(贪心) 统计字数
戳我穿越:http://acm.hdu.edu.cn/showproblem.php?pid=1735 对于贪心,二分,枚举等基础一定要掌握的很牢,要一步一个脚印走踏实 这是道贪心的题目,要有贪心的意 ...
随机推荐
- Centos7下安装Seafile实现私有网盘
Seafile是一个开源.专业.可靠的云存储平台:解决文件集中存储.共享和跨平台访问等问题,由北京海文互知网络有限公司开发,发布于2012年10月:除了一般网盘所提供的云存储以及共享功能外,Seafi ...
- loadrunner socket协议问题归纳(5)
获取服务器的返回值,可以用web_reg_save_param函数,该参数最好放到: 语法: int web_reg_save_param(const char *ParamName, <lis ...
- Alpha阶段中间产物——GUI Prototype、WBS及PSP
作业地址:https://edu.cnblogs.com/campus/nenu/SWE2017FALL/homework/1224 内容: GUI Prototype 我的书架 我的书架→添加图书 ...
- 六周psp
本周psp 本周进度条 代码累积折线图 博文字数累积折线图 饼状图
- c# 消息机制篡改
1.背景介绍: c#程序想要针对某个的消息进行别的行为.例如:窗体不可拖动. 2.应用函数WinProc 以窗口不可拖动举例: const int WM_NCLBUTTONDOWN = 0x00A1; ...
- 微信小程序 功能函数 touch触摸计时
shiFN:function(e){ // touchstart // touchend let that=this; let n=0; // 判断是开始还是结束的参数 let textTure = ...
- opencv 矩阵类数据的运算
参考:http://blog.sina.com.cn/s/blog_7908e1290101i97z.htmlhttp://blog.sina.com.cn/s/blog_afe2af380101bq ...
- js & 快捷键
js & 快捷键 demo js-keyboard-shortcuts.html https://codepen.io/webgeeker/pen/MLYrNq let isCtrl = fa ...
- Delphi定位TDataSet数据集最后一条记录
dst_temp.last ;//最后一条dst_temp.first ;//第一条dst_temp.next ;//下一条dst_temp.prior;//上一条
- 【经典数据结构】Trie
在计算机科学中,trie,又称前缀树或字典树,是一种有种树,用于保存关联数组,其中的键通常是字符串.与二叉查找树不同,键不是直接保存在节点中,而是由节点在树中的位置决定.一个节点的所有子孙都有相同的前 ...