hduoj 1251 统计难题
http://acm.hdu.edu.cn/showproblem.php?pid=1251
统计难题
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)
Total Submission(s): 21236 Accepted Submission(s): 9145
注意:本题只有一组测试数据,处理到文件结束.
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
#include<string>
#include<cmath>
using namespace std;
char ss[][];
#define MAX 27
struct trie
{
trie *next[MAX];
int v;
trie()
{
int i;
v=;
for(i=; i<; i++) next[i]=NULL;
}
};
trie *p,*q;
void creattrie(char *str,trie *root)
{
int len = strlen(str);
p = root;
for(int i=;i<len; i++)
{
int id = str[i] - 'a';
if(p->next[id] == NULL)
{
q=new trie;
q->v = ;
p->next[id] = q;
p=q;
}
else
{
p=p->next[id];
p->v+=;
}
}
}
int findtrie(char *str,trie *root)
{
int i;
int len = strlen(str);
p = root;
for(i=;i<len;i++)
{
int id = str[i] - 'a';
p=p->next[id];
if(p->v == )
{
return i+;
}
}
}
int main()
{
int T,n,ans;
scanf("%d",&T);
while(T--)
{
ans = ;
trie *root = new trie;
scanf("%d",&n);
//getchar();
for(int i=;i<n;i++)
{
scanf("%s", ss[i]);//用gets接收会有WA
creattrie(ss[i],root);
}
for(int i=;i<n;i++)
{
int kk = findtrie(ss[i],root);
ans = ans+kk;
}
printf("%d\n",ans);
}
return ;
}
hduoj 1251 统计难题的更多相关文章
- hdu 1251 统计难题(字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251 统计难题 Time Limit: 4000/2000 MS (Java/Others) M ...
- HDU 1251 统计难题 (Trie)
pid=1251">统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/ ...
- hdu 1251 统计难题 (字典树入门题)
/******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu. ...
- HDU 1251 统计难题(Trie模版题)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Total Subm ...
- HDU 1251统计难题
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- hdu 1251:统计难题(字典树,经典题)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- hdu 1251 统计难题 trie入门
统计难题 Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本 ...
- [ACM] hdu 1251 统计难题 (字典树)
统计难题 Problem Description Ignatius近期遇到一个难题,老师交给他非常多单词(仅仅有小写字母组成,不会有反复的单词出现),如今老师要他统计出以某个字符串为前缀的单词数量(单 ...
- HDU 1251 统计难题 (字符串-Trie树)
统计难题 Problem Description Ignatius近期遇到一个难题,老师交给他非常多单词(仅仅有小写字母组成,不会有反复的单词出现),如今老师要他统计出以某个字符串为前缀的单词数量(单 ...
随机推荐
- 【BZOJ1671】[Usaco2005 Dec]Knights of Ni 骑士 BFS
[Usaco2005 Dec]Knights of Ni 骑士 Description 贝茜遇到了一件很麻烦的事:她无意中闯入了森林里的一座城堡,如果她想回家,就必须穿过这片由骑士们守护着的森林.为 ...
- package.json 字段全解析
Name 必须字段. 小提示: 不要在name中包含js, node字样: 这个名字最终会是URL的一部分,命令行的参数,目录名,所以不能以点号或下划线开头: 这个名字可能在require()方法中被 ...
- DOTA 2 Match History WebAPI(翻译)
关于DOTA 2 Match History WebAPI 的 源网页地址: http://dev.dota2.com/showthread.php?t=47115 由于源网页全英文,这边做下翻译方便 ...
- 第三方登录分享功能-ShareSDK for iOS适配问题记录
最近app里需要添加第三方授权登陆和分享的功能,选择了ShareSDK,参考了ShareSDK文档对该SDK进行了适配,但遇到了一些问题 1.问题:分享功能点击不跳转 原因:适配iOS9添加白名单 ...
- Unity: Passing Constructor Parameters to Resolve
In this tutorial we will go through of couple different ways of using custom constructor parameters ...
- HDU 1892 See you~ (二维树状数组)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1892 See you~ Problem Description Now I am leaving h ...
- arcmap配置的mxd慢的问题
http://www.360doc.com/content/13/0220/09/3046928_266688511.shtml
- *HDU1142 最短路+记忆化dfs
A Walk Through the Forest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- Learn ZYNQ (8)
在zed的PS端运行spark(已成功): (1)设置uboot为sd卡启动rootfs: "sdboot=if mmcinfo; then " \ ...
- CNUOJ 535 黑魔法师之门
先摆出题 难度级别:C: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 背景: 经过了16个工作日的紧张忙碌,未来的人类终于收集到了足够的能源 ...