【POJ 3630】 Phone List
【题目链接】
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的更多相关文章
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
- BZOJ2296: 【POJ Challenge】随机种子
2296: [POJ Challenge]随机种子 Time Limit: 1 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 114 Solv ...
- BZOJ2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 513 Solved: 201[Submit][ ...
- 【POJ 1125】Stockbroker Grapevine
id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...
随机推荐
- Microsoft SQL Server学习(二)--数据库的语法
关于数据库的语法 创建数据库 样例 名词概念 编写数据库代码的注意事项 关于文件语法 实例代码 关于数据库的语法: 1.创建数据库 create database 数据库名 on primary (主 ...
- 2015.12.20-2015.12.25 大论文迭代 A
进一步充实大论文内容.结构,完善一遍大论文 12.20周天,完成论文第五章总结部分,和第一章的修改 12.21周一,完成论文第二章的修改充实 12.22周二,完成论文第三章的修改充实 12.23周三, ...
- mvc 类中对应数据库属性
[StringLength()] //可空 对应数据库可空 [DefaultValue("")] [DisplayName("添加人用户名")] public ...
- RocketMQ学习笔记(4)----RocketMQ搭建双Master集群
前面已经学习了RockeMQ的四种集群方式,接下来就来搭建一个双Master(2m)的集群环境. 1. 双Master服务器环境 序号 ip 用户名 密码 角色 模式 (1) 47.105.145.1 ...
- Redis 之仿微博demo
一.用户注册登录 include './header.php'; include './function.php'; $username = p('username'); $password = p( ...
- Python-暑期实训day 1
python基础: 一 编程语言 什么是编程语言? 上面提及的能够被计算机所识别的表达方式即编程语言,语言是沟通的介质,而编程语言是程序员与计算机沟通的介质.在编程的世界里,计算机更像是人的奴隶,人类 ...
- Excel 导入 分批导入
tm.begin(); sm.begin(); try { result = excel.readE(headKeyV,path); for (int index = 1; index < re ...
- PAT 1104 Sum of Number Segments
Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For exam ...
- 获取当前日期,或指定日期的农历js代码
时间不早了,直接上代码啦-- var CalendarData=new Array(100);var madd=new Array(12);var tgString="甲乙丙丁戊己庚辛壬癸& ...
- hdu 4171 最短路
#include<stdio.h> #include<string.h> #include<queue> #include<iostream> usin ...