2013级测试赛 -- A (字典树)
来源:互联网 发布:淘宝上的凯威淘淘通讯 编辑:程序博客网 时间:2024/05/16 17:26
A
Time Limit: 60MS Memory limit: 65536K
题目描述
给出n(1<= n && n <= 2*10^6)个字符串,每个字符串只包含小写英文字母,且最多有五个。问这n个字符串中出现次数最多的有多少个。
输入
单组输入。第一行输入一个数字n,接下来n行,每行包含一个字符串。
输出
输出一个数字代表答案。
示例输入
5abaabbwabaz
示例输出
2
一开始毫无思路,暴力指定超时,没有想到用字典树,要不是WJJ这题A不了。。
#include <iostream>#include <stdio.h>#include <string.h>#include <stdlib.h>using namespace std;const int N=26; int ma=0;struct node{ struct node *next [N]; int f;};struct node *creat (){ struct node *t; t=(struct node *)malloc (sizeof (struct node)); for (int i=0; i<N; i++) t->next[i]=NULL; t->f=0; return t;};void jia (struct node *t,char *a){ int n=strlen (a); int ans ; for (int i=0; i<n; i++) { ans = a[i]-'a'; if (t->next[ans]==NULL) t->next[ans]=creat (); t=t->next[ans]; } t->f++; if (t->f > ma) ma=t->f;};int main (){ struct node *tree; int n; char a[10]; tree= creat (); scanf ("%d",&n); for (int i=0; i<n; i++) { scanf("%s",a); jia (tree,a); } printf ("%d\n",ma); return 0;}
0 0
- 2013级测试赛 -- A (字典树)
- 测试赛A - Colored Sticks(并查集+字典树+欧拉回路)
- A(SDUT-OJ 2892)----字典树
- A - Message Flood(字典树)
- CodeForces - 566A Matching Names(字典树)
- HDU6191Query on A Tree(字典树启发式合并)
- hdu4760 字典树 (2013网络赛)
- 寒假训练--字典树--A - Immediate Decodability
- 比赛 A - Phone List(字典序)
- hdu 6191 Query on A Tree(字典树启发式合并(动态建树) 可持久化字典树+dfs序)
- Codevs 4189 字典(字典树Trie)
- CF 260 DIV2 D. A Lot of Games(字典树+博弈)
- 2017广西邀请赛 Query on A Tree(可持久化字典树)
- HDU 6191 && 2017广西邀请赛:Query on A Tree(字典树启发式合并)
- 2017 广西邀请赛&& hdu 6191 Query on A Tree(字典树启发式合并)
- 字典树(边改边抄)
- 字典树(Trie)
- 字典树(TrieTree)
- Codeforces 346C Number Transformation II 构造
- 第04章 JSP处理XML
- HDU 4366 Successor 线段树
- 给字符串s1、s2,在s1中找包含s2里所有字符的最小子串
- 课程设计
- 2013级测试赛 -- A (字典树)
- 第05章 JSP整合Ajax
- Unity3D 玻璃 Shader
- 在 MATLAB 2012a 上配置 MATLAB Distributed Computing Server过程详解
- FlatBuffers要点
- 第06章 JSP Ajax常用技巧
- hdu1671 字典树记录前缀出现次数
- 第07章 Ajax框架
- 最小生成树——克鲁斯卡尔