题意:给一组串,是否存在一个串是另一个的前缀。

分析:val[N]保存树节点上是否组成一个串

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
#define N 100010
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
struct Trie{
int ch[N][];
int val[N],num;
void init(){
num=;
memset(ch[],,sizeof(ch[]));
}
int idx(char c){return c-'';}
int build(char *s){
int u=,len=strlen(s),f=;
for(int i=;i<len;++i){
int v=idx(s[i]);
if(!ch[u][v]){
memset(ch[num],,sizeof(ch[num]));
val[num]=;
ch[u][v]=num++;
f=;
}
u=ch[u][v];
if(val[u]==)return ;
}
if(val[u]==)return ;
val[u]=;
if(!f)return ;
return ;
}
}trie;
int main()
{
int t,n;
char str[];
scanf("%d",&t);
while(t--){
trie.init();
scanf("%d",&n);
int f=;
for(int i=;i<n;++i){
scanf("%s",str);
if(f){
f=trie.build(str);
}
}
if(f)printf("YES\n");
else printf("NO\n");
}
return ;
}

POJ 3630- Phone List(Trie)的更多相关文章

  1. POJ 3630 Phone List(trie树的简单应用)

    题目链接:http://poj.org/problem?id=3630 题意:给你多个字符串,如果其中任意两个字符串满足一个是另一个的前缀,那么输出NO,否则输出YES 思路:简单的trie树应用,插 ...

  2. POJ 3669 Meteor Shower(流星雨)

    POJ 3669 Meteor Shower(流星雨) Time Limit: 1000MS    Memory Limit: 65536K Description 题目描述 Bessie hears ...

  3. POJ 3253 Fence Repair (优先队列)

    POJ 3253 Fence Repair (优先队列) Farmer John wants to repair a small length of the fence around the past ...

  4. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

  5. Poj 3613 Cow Relays (图论)

    Poj 3613 Cow Relays (图论) 题目大意 给出一个无向图,T条边,给出N,S,E,求S到E经过N条边的最短路径长度 理论上讲就是给了有n条边限制的最短路 solution 最一开始想 ...

  6. 【python】Leetcode每日一题-前缀树(Trie)

    [python]Leetcode每日一题-前缀树(Trie) [题目描述] Trie(发音类似 "try")或者说 前缀树 是一种树形数据结构,用于高效地存储和检索字符串数据集中的 ...

  7. POJ 1251 Jungle Roads (prim)

    D - Jungle Roads Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Su ...

  8. LA3942-Remember the Word(Trie)

    题意: 有s个不同的单词,给出一个长字符串把这个字符串分解成若干个单词的连接(可重复使用),有多少种分解方法 分析: dp[i]表示i开始的字符串能分解的方法数 dp[i]=sum(dp[i+len( ...

  9. HDU 1671 Phone List (Trie)

    pid=1671">Phone List Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  10. poj 1284 Primitive Roots (原根)

    Primitive Roots http://poj.org/problem?id=1284 Time Limit: 1000MS   Memory Limit: 10000K       Descr ...

随机推荐

  1. XML工具类 - XmlUtils.java

    XML工具类,提供序列化XML.反序列化XML.获取指定节点的值的方法. 源码如下:(点击下载 - XmlUtils.java.dom4j-1.6.1.jar.xstream-1.4.7.jar ) ...

  2. IntPtr

    一:什么是IntPtr 先来看看MSDN上说的:用于表示指针或句柄的平台特定类型.这个其实说出了这样两个事实,IntPtr 可以用来表示指针或句柄.它是一个平台特定类型.对于它的解释,这个哥们写的比较 ...

  3. 1305: [CQOI2009]dance跳舞 - BZOJ

    Description 一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞.每个男孩都不会和同一个女孩跳两首(或更多)舞曲.有一些男孩女孩相互喜欢,而其他相互不喜欢(不会 ...

  4. 如何助力企业 APP 在竞争中占据先机?

    做好产品的六字真言:刚需.痛点.高频 --周鸿祎 好的产品是需要不断打磨的.在开发任何产品之前,都需要进行严格的假设和调研,找到刚需,找到痛点.然后就是不断的验证自己的假设,不断地在适当的试错过程中成 ...

  5. HDU1796+容斥原理

    给定n和m个数,询问在小于n的数中 有多少个能整除m中的某个数.. 容斥原理. PS:注意64位整数! /* 容斥原理 */ #include<stdio.h> #include<s ...

  6. hdu 1851 A Simple Game 博弈论

    简单博弈问题(巴什博弈-Bash Game) 巴什博弈:只有一堆n个物品,两个人轮流从这对物品中取物,规定每次至少取一个,最多取m个,最后取光着得胜. 很容易想到当n%(m+1)!=0时,先取者必胜, ...

  7. highcharts 多数据+切换

    var highchartsOptions = { chart:{ renderTo:'container' }, title:{ text:'指标数据' }, tooltip:{ pointForm ...

  8. js监听输入框值的即时变化onpropertychange、oninput

    js监听输入框值的即时变化onpropertychange.oninput 很多情况下我们都会即时监听输入框值的变化,以便作出即时动作去引导浏览者增强网站的用户体验感. // //   要达到的效果 ...

  9. Java API ——Arrays类

    1.Arrays类概述 · 针对数组进行操作的工具类. · 提供了排序,查找等功能. 2.成员方法 · public static String toString(int[] a):in[] a可以改 ...

  10. HTML5 JS API 本地存储LocalStorage基本操作

    LocalStorage:使用方法与SessionStorage如出一辙,如下代码所示:此对象主要有两个方法:保存数据:localStorage.setItem(Key, value);读取数据:lo ...