首页 > 其他 > 详细

hdu 3460 Ancient Printer

时间:2015-06-03 17:07:48      阅读:241      评论:0      收藏:0      [点我收藏+]

答案=字典树节点个数+单词个数-最长的单词的长度。表示不会推倒。看了大牛博客。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

struct shu{ int nn[27]; }node[500010];
int ii, i, n, m, zz, tott, hh;
char s[10000];

int main()
{ 
    
    while (~scanf("%d", &n))
    {
        for (i = 0; i <= 500000; i++)
            memset(node[i].nn, -1, sizeof(node[i].nn));
        tott = 1; hh = -1;
        for (ii = 0; ii < n; ii++)
        {
            scanf("%s", s);
            int len = strlen(s);
            if (len>hh) hh = len;
            zz = 0;
            for (i = 0; s[i]; i++)
            {
                if (node[zz].nn[s[i] - a] == -1)
                {
                    node[zz].nn[s[i] - a] = tott;
                    tott++;
                }
                zz = node[zz].nn[s[i] - a];
            }
        }
        printf("%d\n", (tott - 1) * 2 + n - hh);
    }
    return 0;
}

 

hdu 3460 Ancient Printer

原文:http://www.cnblogs.com/zufezzt/p/4549420.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!