Balala Power!

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 714    Accepted Submission(s): 117

Problem Description

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 froma 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.

 
Input
The input contains multiple test cases.

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)

 
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
1
a
2
aa
bb
3
a
ba
abc
 
Sample Output
Case #1: 25
Case #2: 1323
Case #3: 18221
 
//题意:有 n 个小写的字符串,想要把它们变为 26 进制的 0-25 的数字,问 n 个数最大的和为多少?还有,不能有前导0,除非就是0
 
题解:每个字母,在任意位置都会有个权值,统计所有字母的权值,但是只能用大数保存,保存完后。按字母权值排序,最大的赋 24 ,类推,然后考虑可能前导 0 的情况,如果,找到不会作为前导的数后,,关键是,不能交换,而是整体向上平移 1 ,这样才能保证是最大值
  1. #include <iostream>
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include <algorithm>
  5. using namespace std;
  6. #define LL long long
  7. #define MOD 1000000007
  8. #define MX 100100
  9.  
  10. int n;
  11. int al_n[];
  12. LL num[][MX];
  13. LL quan[];
  14. char temp[MX];
  15. bool ok[];
  16.  
  17. bool cmp(int a,int b)
  18. {
  19. if (al_n[a]!=al_n[b])
  20. return al_n[a]>al_n[b];
  21.  
  22. for (int i=al_n[a];i>=;i--)
  23. if (num[a][i]!=num[b][i])
  24. return num[a][i]>num[b][i];
  25.  
  26. return ;
  27. }
  28.  
  29. int main()
  30. {
  31. int cnt=;
  32. while (scanf("%d",&n)!=EOF)
  33. {
  34. memset(quan,,sizeof(quan));
  35. memset(num,,sizeof(num));
  36. memset(ok,,sizeof(ok));
  37.  
  38. for (int i=;i<n;i++)
  39. {
  40. scanf("%s",temp);
  41. int len = strlen(temp);
  42. LL k=;
  43. for (int j=len-;j>=;j--)
  44. {
  45. num[temp[j]-'a'][k]++;
  46. k++;
  47. }
  48. if (len!=)
  49. ok[temp[]-'a']=;
  50. }
  51.  
  52. for (int i=;i<;i++)//字母
  53. {
  54. al_n[i]=;
  55. for (int j=;j<MX;j++) //长度
  56. {
  57. if (num[i][j]) al_n[i]=j;
  58. if (num[i][j]>=)
  59. {
  60. int jin = num[i][j]/;
  61. num[i][j+]+=jin;
  62. num[i][j]%=;
  63. }
  64. }
  65. }
  66.  
  67. int alpa[];
  68. for (int i=;i<;i++) alpa[i]=i;
  69. sort(alpa,alpa+,cmp);
  70.  
  71. if (al_n[alpa[]]!=&&ok[alpa[]]==)
  72. {
  73. for (int i=;i>=;i--)
  74. {
  75. if (ok[alpa[i]]==)
  76. {
  77. int sbsb=alpa[i];
  78. for (int j=i+;j<=;j++)
  79. alpa[j-]=alpa[j];
  80. alpa[]=sbsb;
  81. break;
  82. }
  83. }
  84. }
  85.  
  86. LL ans = ;
  87. LL qqq = ;
  88. for (int i=;i<;i++)
  89. {
  90. int zimu = alpa[i];
  91. if (al_n[zimu]==) continue;
  92. LL tp=qqq;
  93. for (int j=;j<=al_n[zimu];j++)
  94. {
  95. ans = (ans + (tp * num[zimu][j])%MOD)%MOD;
  96. tp=(tp*)%MOD;
  97. }
  98. qqq--;
  99. }
  100. printf("Case #%d: %lld\n",cnt++,ans);
  101. }
  102. return ;
  103. }

Balala Power!(大数+思维)的更多相关文章

  1. HDU 6034 17多校1 Balala Power!(思维 排序)

    Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He want ...

  2. HDU 6034 - Balala Power! | 2017 Multi-University Training Contest 1

    /* HDU 6034 - Balala Power! [ 大数进位,贪心 ] 题意: 给一组字符串(小写英文字母),将上面的字符串考虑成26进制数,每个字母分配一个权值,问这组数字加起来的和最大是多 ...

  3. HDU 6034 Balala Power!【排序/进制思维】

    Balala Power![排序/进制思维] Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java ...

  4. 2017 多校训练 1002 Balala Power!

    Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  5. 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 ...

  6. hdu 6034 B - Balala Power! 贪心

    B - Balala Power! 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6034 题面描述 Talented Mr.Tang has n st ...

  7. hdu 6034 Balala Power!

    Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  8. 2017ACM暑期多校联合训练 - Team 1 1002 HDU 6034 Balala Power! (字符串处理)

    题目链接 Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He ...

  9. HDU 6034 Balala Power!(贪心+排序)

    Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

随机推荐

  1. lodash forIn forOwn 遍历对象属性

    _.forIn(object, [iteratee=_.identity]) 使用 iteratee 遍历对象的自身和继承的可枚举属性. function Foo() { this.a = 1; th ...

  2. ViewPager中Fragment无法显示的问题

    问题描述: Actvitiy->Fragment1 ->Fragment2 Fragment1中有1个ViewPager,ViewPager里面有包括了2个Fragment. 当第一次执行 ...

  3. iOS 物流信息时间轴

    代码地址如下:http://www.demodashi.com/demo/11958.html timelineLogistics 是模仿淘宝物流信息时间轴界面的自定义View 准备工作 引入Maso ...

  4. lucene 搜索优化,个人实战经验总结

    1.IndexSearch.IndexReader等都是线程安全的类,多线程并发使用是没有问题的.不到忘不得以,尽量避免重新实例化,他们实例化是很花费时间的,看一下他们的构造原理你就知道了.   2. ...

  5. android推送方式

    本文介绍在Android中实现推送方式的基础知识及相关解决方案.推送功能在手机开发中应用的场景是越来起来了,不说别的,就我们手机上的新闻客户端就时不j时的推送过来新的消息,很方便的阅读最新的新闻信息. ...

  6. Titel Block不显示

    在原有原理图上New page时不显示Titel Block 解决办法:两种(1)(2) 方法1.在新建的原理图上右键选择Schematic Page Properties,按下图勾选即可 方法2.进 ...

  7. Restore IP Addresses -- LeetCode

    原题链接: http://oj.leetcode.com/problems/restore-ip-addresses/  这道题的解法很接近于NP问题.也是採用递归的解法. 基本思路就是取出一个合法的 ...

  8. centos6安装docker

    rpm -ivh http://dl.Fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm rpm --import /etc ...

  9. Who's in the Middle - poj 2388 (快速排序寻找中位数)

    题意; 寻找中位数 利用快速排序来寻找中位数. #include <iostream> using namespace std; int N; ]; int Median(int left ...

  10. 整理mp4协议重点,将协议读薄

    MP4 实际代表的含义是 MPEG-4 Part 14.它只是 MPEG 标准中的 14 部分.它主要参考 ISO/IEC 标准来制定的.MP4 主要作用是可以实现快进快放,边下载边播放的效果.他是基 ...