zoukankan      html  css  js  c++  java
  • 第一场 hdu 6034 Balala Power!


    Talented Mr.Tang has nn strings consisting of only lower case characters. He wants to charge them with Balala Power (he could change each character ranged from a to zinto 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 2626 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+7109+7.

    InputThe input contains multiple test cases. 

    For each test case, the first line contains one positive integers nn, the number of strings. (1n100000)(1≤n≤100000) 

    Each of the next nn lines contains a string sisi consisting of only lower case letters.(1|si|100000,|si|106)(1≤|si|≤100000,∑|si|≤106) 
    OutputFor each test case, output " Case #xx: yy" in one line (without quotes), where xxindicates the case number starting from 11 and yy 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,求这n行字符串相加的和是多少??

    解题思路:首先使用二维数组记录字符串的位置上的字符和一维数组第一个字符进行统计,然后用二维数组对结构体进行排序,从大到小将不是前导的字符赋值为0,从小到大对不是0的字符由25开始往0对字符进行赋值,最后对于二维数组进行计数,打印结果即可。

    AC代码:

     
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <algorithm>
     5 #include <cmath>
     6 using namespace std;
     7 const int eps=1e9+7;
     8 long long a[100005][30],flag[100005];
     9 char s[100005];
    10 long long ans[30];
    11 int step,num[30],cnt[30];
    12 int cmp(int A,int B)
    13 {
    14     for(int i=step;i>=0;i--)
    15     {
    16         if(a[i][A]!=a[i][B])
    17         return a[i][A]<a[i][B];
    18     }
    19     return A<B;
    20 }
    21 int main()
    22 {
    23     flag[0]=1;
    24     for(int i=1;i<100003;i++)
    25     flag[i]=(long long)(flag[i-1]*26)%eps;
    26     int n,cas=0;
    27     //freopen("1002.in","r",stdin);
    28     //freopen("1002.out","w",stdout);
    29     while(~scanf("%d",&n))
    30     {
    31         cas++;
    32         memset(ans,0,sizeof(ans));
    33         memset(cnt,0,sizeof(cnt));
    34         memset(a,0,sizeof(a));
    35         step=0;
    36         for(int i=0;i<n;i++)
    37         {
    38             scanf("%s",s);
    39             int len=strlen(s);
    40             if(len>1)
    41             cnt[s[0]-'a']=1;
    42             reverse(s,s+len);
    43             for(int j=0;j<len;j++)
    44             {
    45                 a[j][s[j]-'a']++;
    46             }
    47             step=max(step,len);
    48         }
    49         for(int i=0;i<26;i++)
    50         {
    51             for(int j=0;j<step;j++)
    52             {
    53                 a[j+1][i]+=a[j][i]/26;
    54                 a[j][i]=a[j][i]%26;
    55             }
    56             while(a[step][i])
    57             {
    58                 a[step+1][i]+=a[step][i]/26;
    59                 a[step][i]=a[step][i]%26;
    60                 step++;
    61             }
    62             num[i]=i;
    63         }
    64         sort(num,num+26,cmp);
    65         int zero=-1;
    66         for(int i=0;i<26;i++)
    67         {
    68             if(!cnt[num[i]])
    69             {
    70                 zero=num[i];
    71                 break;
    72             }
    73         }
    74         int k=25;
    75         for(int i=25;i>=0;i--)
    76         {
    77             if(zero!=num[i])
    78             {
    79                 ans[num[i]]=k;
    80                 k--;
    81             }
    82         }
    83         long long key=0;
    84         for(int i=0;i<step;i++)
    85         {
    86             for(int j=0;j<26;j++)
    87             {
    88                 key=(key+(ans[j]*flag[i]*a[i][j]))%eps;
    89             }
    90         }
    91         printf("Case #%d: %lld
    ",cas,key);
    92     }
    93     return 0;
    94 }
    View Code
  • 相关阅读:
    centos linux系统日常管理3 服务管理ntsysv,chkconfig,系统日志rsyslog,last ,lastb ,exec,xargs,dmesg,screen,nohup,curl,ping ,telnet,traceroute ,dig ,nc,nmap,host,nethogs,base64,jq 第十六节课
    centos Linux系统日常管理2 tcpdump,tshark,selinux,strings命令, iptables ,crontab,TCP,UDP,ICMP,FTP网络知识 第十五节课
    一个兼职DBA的数据库运维经验 小米科技 xx@xiaomi.com 2011
    centos Linux系统日常管理1 cpuinfo cpu核数 命令 w, vmstat, uptime ,top ,kill ,ps ,free,netstat ,sar, ulimit ,lsof ,pidof 第十四节课
    HTML5矢量实现文件上传进度条
    基于HTML5的WebGL呈现A星算法3D可视化
    基于HTML5的WebGL呈现A星算法的3D可视化
    基于HTML5的WebGL设计汉诺塔3D游戏
    基于HTML5树组件延迟加载技术实现
    基于HTML5的WebGL电信网管3D机房监控应用
  • 原文地址:https://www.cnblogs.com/wang-ya-wei/p/7262466.html
Copyright © 2011-2022 走看看