二手tire木;

Basic应用程序

谈到很具体的 点击打开链接

#include<cstdio>
#include<cstring>
#include<iostream>
#define max 20
using namespace std;
char w[6];
struct node{
bool a;
int chile[26];
int q;//前缀出现次数
node(){
q=false;
q=0;
memset(chile,0,sizeof(chile));
}
}t[500000]; int sz=1;
void insert(char *w)
{
int len=strlen(w);
int s=0;
for(int i=0;i<len;i++)
{
int y=w[i]-'a';
if(t[s].chile[y]==0)
{
t[s].chile[y]=sz++;
}
s=t[s].chile[y];//下一个结点
t[s].q++;
}
t[s].a=1;
} int show(char *w)
{
int len=strlen(w);
int s=0;
for(int i=0;i<len;i++)
{
int y=w[i]-'a';
if(t[s].chile[y]==0)
return 0;
s=t[s].chile[y];
}
return t[s].q;
}
int main()
{
char s[50];
while(gets(s))
{
int len=strlen(s);
if(len==0) break;
insert(s);
}
while(gets(s))
{
printf("%d\n",show(s));
}
return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

hdu 1251 统计拼图的更多相关文章

  1. HDU 1251 统计拼图 Trie解决问题的方法

    基本上找到一个标准前缀的问题是,只需要insert和search它功能. 这里的主要变化是我n该记录方法,这里n国旗代表的不是叶节点,但是话的标志这条道路后的数字. 然后找到需要找到一个词的前缀,假如 ...

  2. hdu 1251 统计难题 (字典树入门题)

    /******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu. ...

  3. HDU 1251 统计难题(Trie模版题)

    统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others) Total Subm ...

  4. hdu 1251 统计难题(字典树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251 统计难题 Time Limit: 4000/2000 MS (Java/Others)    M ...

  5. HDU 1251 统计难题 (Trie)

    pid=1251">统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/ ...

  6. hdu 1251 统计难题(trie 树的简单应用)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意:给你多个字符串,求以某个字符串为前缀的字符串数量. 思路:简单的trie数应用,在trie ...

  7. HDU 1251 统计难题(字典树模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意:给出一些单词,然后有多次询问,每次输出以该单词为前缀的单词的数量. 思路: 字典树入门题. #inc ...

  8. HDU 1251 统计难题(字典树 裸题 链表做法)

    Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己 ...

  9. 字典树 HDU 1251 统计难题

    ;} 之前写的#include<iostream> #include<algorithm> #include<stdio.h> using namespace st ...

随机推荐

  1. hdu4493 Tutor

    Tutor Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) Total Submiss ...

  2. HDU 4597 Play Game 2013 ACM-ICPC吉林通化全国邀请赛H题

    九野的博客,转载请注明出处:  http://blog.csdn.net/acmmmm/article/details/10833941 题意:给定T个测试数据,下面有2副牌,每副n张,每张都有一个分 ...

  3. leetcode解析回文子串拆分

    转载请注明来自souldak,微博:@evagle Given a string s, partition s such that every substring of the partition i ...

  4. zoj 2822 Sum of Different Primes (01背包)

    ///给你n 求他能分解成多少个的不同的k个素数相加之和 ///01背包,素数打表 # include <stdio.h> # include <algorithm> # in ...

  5. SPOJ PGCD(莫比乌斯反演)

    传送门:Primes in GCD Table 题意:给定两个数和,其中,,求为质数的有多少对?其中和的范围是. 分析:这题不能枚举质数来进行莫比乌斯反演,得预处理出∑υ(n/p)(n%p==0). ...

  6. python(abi) RPM DEB Download

    python(abi) RPM DEB Download python(abi) RPM DEB Download

  7. C#获取Excel中所有的Sheet名称

    原文地址:http://blog.csdn.net/qq1010726055/article/details/6858849 Excel.Application myExcel = new Excel ...

  8. xcode多target

    原文:http://www.codza.com/free-iphone-app-version-from-the-same-xcode-project There are more than 15,0 ...

  9. SE 2014 年4月21日(二)

    实验练习: 如图配置: 两BGP自治系统,要求建立相关BGP邻居关系 1. 建立BGP邻居关系 要求使用BGP对等体组完成(IBGP要求使用loopback接口作为TCP建立的源接口) 2. R3 R ...

  10. extjs4 分页工具栏pagingtoolbar的每页显示数据combobox下拉框

    var itemsPerPage = 20; var combo; //创建数据源store Ext.define('recordStore', { extend : 'Ext.data.Store' ...