【题目链接】

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. RTL Compiler之synthesis flow

    1 generic RTL Compiler work flow 2 invoking RTL compiler RTL Compiler is invoked from the operating ...

  2. Redis 之消息发布与订阅(publish、subscribe)

    使用办法: 订阅端: Subscribe 频道名称 发布端: publish 频道名称 发布内容 一般做群聊,聊天室,发布公告信息等.

  3. js的三种对象

    JS中,可以将对象分为“内部对象”.“宿主对象”和“自定义对象”三种. 1,内部对象 js中的内部对象包括Array.Boolean.Date.Function.Global.Math.Number. ...

  4. Netty 长连接服务

    转自:https://www.dozer.cc/2014/12/netty-long-connection.html 推送服务 还记得一年半前,做的一个项目需要用到 Android 推送服务.和 iO ...

  5. JeePlus 工作流版本 sping mvc oa crm erp java html5 源码

    https://shop108220642.taobao.com/search.htm?spm=2013.1.w5002-5297459241.1.mnhAZ5&search=y http:/ ...

  6. [C#] 序列化实现对象的深拷贝

    //对象深拷贝 public static T Copy<T>(T oldObject) where T : class,new() { T newOrder = new T(); Mem ...

  7. web前端习总结--JavaScript

    JavaScript 什么是JavaScript JavaScript是嵌入HTML中在浏览器中的脚本语言,有与Java和C语言类似的语法 一种网页编程技术,用来向HTML页面添加交互行为 直接嵌入H ...

  8. 百度编辑器ueditor1.4.3配置记录

    我从官网下载的php文件,但是图片上传不能用,后来查找资料,打开ueditor下的php/controller.php,(其他环境选对应的文件夹)把时区设置按如下改个字母大小写,再打开该文件就正确返回 ...

  9. Python 4 循环语句while

    while  [条件]:        条件这里满足布尔运算True则无限循环while里面代码. 固定条件的 基本的while循环, 如果if匹配那么 则执行打印登录成功,和break跳出整个循环, ...

  10. Mysql双主自增长冲突处理

    Mysql双主自增长冲突处理   多主互备和主从复制有一些区别,因为多主中都可以对服务器有写权限,所以设计到自增长重复问题   出现的问题(多主自增长ID重复)  1:首先我们通过A,B的test表结 ...