【题目链接】

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. 【PostgreSQL-9.6.3】分区表

    PostgreSQL中的分区表是通过表继承来实现的(表继承博客http://www.cnblogs.com/NextAction/p/7366607.html).创建分区表的步骤如下: (1)创建“父 ...

  2. html5——拖拽

    基本情况 在HTML5的规范中,我们可以通过为元素增加draggable="true"来设置此元素是否可以进行拖拽操作,其中图片.链接默认是开启的. 拖拽元素 页面中设置了drag ...

  3. [Windows Server 2008] 服务器安全加固

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:服务器安全加固 ...

  4. c#仿照qq登录界面编辑框内容操作

    using System; using System.Drawing; using System.Windows.Forms; namespace 案例演示 { public partial clas ...

  5. Android之手机振动和振铃

    一.振动的实现1.使用振动所需的权限 <uses-permission android:name="android.permission.VIBRATE" />2.相关 ...

  6. iptables详解(2):iptables实际操作之规则查询

    所属分类:IPtables  Linux基础 在阅读这篇文章之前,请确保你已经阅读了如下文章,如下文章总结了iptables的相关概念,是阅读这篇文章的基础. 图文并茂理解iptables 如果你是一 ...

  7. [LUOGU] 1108 低价购买

    统计本质不同的\(LIS\)个数. 因为本题要求的是\(N^2\)级别的算法,就直接暴力统计\(LIS\)的个数了 然后统计方案数的话加入发现有之间有一个值,以它为结尾的\(LIS\)长度和当前的相等 ...

  8. BUAA_OO_博客作业二

    1.作业设计策略 1.1第一次作业 ​ 第一次作业指导书要求是一个单部多线程傻瓜调度(FAFS)电梯的模拟,由于为了可扩展性和模块化设计,第一次作业我采用了三线程,即输入处理线程,调度器线程,电梯线程 ...

  9. 用Twebbrowser做可控编辑器与MSHTML

    首先要明白mshtml的属性方法: {IHTMLDocument2 方法:} write //写入 writeln //写入并换行 open //打开一个流,以收集 document.write 或 ...

  10. windows下swoole安装教程

    1)下载安装cygwin(根据操作系统选择32位或者64位): https://cygwin.com/install.html 选择在windows中虚拟环境的root目录 选择下载安装的网络节点,如 ...