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

分析: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. sharepoint One-Time Passwords (windows basic authentication)

    //设计中,未完成 references: http://www.asp.net/web-api/overview/security/basic-authentication http://techn ...

  2. HttpWebRequest

    同步请求=====================================================================================  byte[] da ...

  3. 简单3d RPG游戏 之 004 攻击(一)

    功能:实现点击键盘F键,怪物血量条减少,并且假定是近战,需要对距离进行判断,距离小于一定值的时候按F才会减少怪物的血条. 新建c#脚本PlayerAttack,绑定到Player,并在unity里将敌 ...

  4. 如何让VS根据编译环境选择相应的配置文件

    其实微软还是蛮有创造力的,一个配置文件居然弄了这么多的形式,从原来的ini到现在的xml,总而言之让我们这些在微软殿堂里的程序员翘着屁股追赶. 微软最新的配置文件实际上就是个xml文件,以后缀名.co ...

  5. 100 doors

    Question There are 100 doors in a row that are all initially closed. You make 100 passes by the door ...

  6. jquery盒模型元素尺寸设置

    jQuery有多个处理元素尺寸的方法 width():设置或返回元素的宽度(不包括padding.border.和margin) height():设置或返回元素的高度(不包括padding.bord ...

  7. mysql 跨库JOIN

    现有两台MYSQL数据库 一台是192.168.1.1 端口3306 上有数据库DB1 有表TABLE1一台是192.168.1.2 端口3307 上有数据库DB2 有表TABLE2192.168.1 ...

  8. c++ 私有函数 头文件设计

    clock.h #ifndef CLOCK_H_INCLUDED #define CLOCK_H_INCLUDED class Clock {public: static void HandleExd ...

  9. Javascript和ECMAScript二三事

    来自<javascript高级程序设计 第三版:作者Nicholas C. Zakas>的学习笔记(一) Javascript是一种专为与网页交互而设计的脚本语言,由下列三个不同部分组成: ...

  10. API HOOK

    API HOOK技术是一种用于改变API执行结果的技术,Microsoft 自身也在Windows操作系统里面使用了这个技术,如Windows兼容模式等. API HOOK 技术并不是计算机病毒专有技 ...