【题目链接】

http://poj.org/problem?id=3630

【算法】

字典树

【代码】

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 10010 int i,TC,n;
bool flag;
char s[MAXN][]; struct info
{
int child[];
bool is_last;
}; class Trie
{
private :
int tot;
info a[MAXN*];
public :
inline void clear(int x)
{
int i;
a[x].is_last = false;
for (i = ; i < ; i++)
{
if (a[x].child[i])
{
tot--;
clear(a[x].child[i]);
a[x].child[i] = ;
}
}
}
inline bool insert(char *s)
{
int i,x = ,len;
bool flag = false;
len = strlen(s);
for (i = ; i < len; i++)
{
if (a[x].child[s[i]-''])
{
x = a[x].child[s[i]-''];
if (a[x].is_last || i == len - ) flag = true;
} else
{
a[x].child[s[i]-''] = ++tot;
x = a[x].child[s[i]-''];
}
}
a[x].is_last = true;
return flag ^ ;
}
} T; int main()
{ scanf("%d",&TC);
while (TC--)
{
flag = true;
T.clear();
scanf("%d",&n);
for (i = ; i <= n; i++) scanf("%s",&s[i]);
for (i = ; i <= n; i++)
{
if (T.insert(s[i])) continue;
else
{
flag = false;
break;
}
}
if (flag) printf("YES\n");
else printf("NO\n");
} return ; }

【POJ 3630】 Phone List的更多相关文章

  1. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  2. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  3. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  4. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  5. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  6. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

  7. BZOJ2296: 【POJ Challenge】随机种子

    2296: [POJ Challenge]随机种子 Time Limit: 1 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 114  Solv ...

  8. BZOJ2292: 【POJ Challenge 】永远挑战

    2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 513  Solved: 201[Submit][ ...

  9. 【POJ 1125】Stockbroker Grapevine

    id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...

随机推荐

  1. 【技术累积】【点】【java】【29】MapUtils

    内容 是Apache组织下的commons-collections包中的工具类 <dependency> <groupId>commons-collections</gr ...

  2. Logstash_Apache日志采集

    [root@Cagios logstash-]# cat /usr/local/logstash-/logstash_agent.conf input { file { type => &quo ...

  3. (转) Arcgis for js之WKT和GEOMETRY的相互转换

    http://blog.csdn.net/gisshixisheng/article/details/44057453 1.wkt简介 WKT(Well-known text)是一种文本标记语言,用于 ...

  4. 6 个 Linux 运维典型问题,大牛的分析解决思路在这里

    作为一名合格的 Linux 运维工程师,一定要有一套清晰.明确的解决故障思路,当问题出现时,才能迅速定位.解决问题,这里给出一个处理问题的一般思路: 重视报错提示信息:每个错误的出现,都是给出错误提示 ...

  5. Vue中.sync修饰符

    Vue 中 sync的作用 <FatherComponent :a.sync = 'b'><FatherComponent /> 子组件中emit('update:a',... ...

  6. JavaScript day4(逻辑运算符)

    逻辑运算符 逻辑运算符用于测定变量或值之间的逻辑 逻辑与运算符:&&.同时满足(and). 通过if语句的嵌套来实现: if (num > 5) { if (num < 1 ...

  7. STL源码分析之迭代器

    前言 迭代器是将算法和容器两个独立的泛型进行调和的一个接口. 使我们不需要关系中间的转化是怎么样的就都能直接使用迭代器进行数据访问. 而迭代器最重要的就是对operator *和operator-&g ...

  8. enote笔记语言(4)(ver0.4)——“5w1h2k”分析法

    章节:“5w1h2k”分析法   what:我想知道某个“关键词(keyword)”(即,词汇.词语,或称单词,可以是概念|专业术语|.......)的定义. why:我想分析and搞清楚弄明白“事物 ...

  9. 18清明校内测试T1

    消失的数字(number) Time Limit:1000ms   Memory Limit:128MB 题目描述 rsy拥有n个数,这n个数分别是a1,a2,…,an. 后来出现了一个熊孩子zhw, ...

  10. cmake编译安装mysql

    运维开发技术交流群欢迎大家加入一起学习(QQ:722381733) 前言:这里我使用的安装方式是(cmake编译),我选择的版本是:cmake-2.8.8.tar.gz.mysql-5.5.32.ta ...