题目:

给定 n 个长度不超过 10 的数字串,问其中是否存在两个数字串 S, T ,使得 S 是 T 的前
缀。多组数据,数据组数不超过 40.


题解:

前缀问题一般都用Trie树解决:

所以跑一个Tire树,记录一下每个节点是不是结尾就好

#include<cstdio>
#include<algorithm>
#include<cstring>
#define N 100010
#define Z 10
using namespace std;
int T,n,tot;
struct node
{
int trans[Z],bo;
void clear()
{
memset(trans,0,sizeof(trans));
bo=0;
}
}tr[N];
char s[20];
int insert(char *s)
{
int len=strlen(s),u=1,flag=0;
for (int i=0;i<len;i++)
{
if (!tr[u].trans[s[i]-'0'])
tr[tr[u].trans[s[i]-'0']=++tot].clear();
else if (i==len-1)
flag=1;
u=tr[u].trans[s[i]-'0'];
if (tr[u].bo) flag=1;
}
tr[u].bo=1;
return flag;
}
int main()
{
scanf("%d",&T);
while (T--)
{
scanf("%d",&n);
tr[tot=1].clear();
int ans=0;
for (int i=1;i<=n;i++)
{
scanf("%s",s);
if (insert(s)) ans=1;
}
if (!ans) puts("YES");
else puts("NO");
}
return 0;
}

POJ 3630 Phone List | Trie 树的更多相关文章

  1. poj 3630 Phone List trie树

    Phone List Description Given a list of phone numbers, determine if it is consistent in the sense tha ...

  2. poj 2513 Colored Sticks (trie 树)

    链接:poj 2513 题意:给定一些木棒.木棒两端都涂上颜色,不同木棒相接的一边必须是 同样的颜色.求能否将木棒首尾相接.连成一条直线. 分析:能够用欧拉路的思想来解,将木棒的每一端都看成一个结点 ...

  3. [ACM] POJ 2418 Hardwood Species (Trie树或map)

    Hardwood Species Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 17986   Accepted: 713 ...

  4. [POJ 1204]Word Puzzles(Trie树暴搜&amp;AC自己主动机)

    Description Word puzzles are usually simple and very entertaining for all ages. They are so entertai ...

  5. poj 3630 Phone List(字典树)

    题目链接: http://poj.org/problem?id=3630 思路分析: 求在字符串中是否存在某个字符串为另一字符串的前缀: 即对于某个字符串而言,其是否为某个字符串的前缀,或存在某个其先 ...

  6. poj 2513 Colored Sticks trie树+欧拉图+并查集

    点击打开链接 Colored Sticks Time Limit: 5000MS   Memory Limit: 128000K Total Submissions: 27955   Accepted ...

  7. POJ 3630 Phone List Trie题解

    Trie的应用题目. 本题有两个难点了: 1 动态建立Trie会超时,须要静态建立数组,然后构造树 2 推断的时候注意两种情况: 1) Tire树有133,然后插入13333556的时候.2)插入顺序 ...

  8. POJ训练计划2418_Hardwood Species(Trie树)

    解题报告 Tire树. #include <iostream> #include <cstring> #include <cstdio> #include < ...

  9. poj 2513 Colored Sticks (trie树+并查集+欧拉路)

    Colored Sticks Time Limit: 5000MS   Memory Limit: 128000K Total Submissions: 40043   Accepted: 10406 ...

随机推荐

  1. Latex 使用笔记,取消目录

    不使用标准模板(如ieee或者acm的模板)的前提下: \usepackage{hyperref} \hypersetup{bookmarks={false}} 或者 \usepackage[book ...

  2. LVS+Keepalived-DR模式负载均衡高可用集群

    LVS+Keepalived DR模式负载均衡+高可用集群架构图 工作原理: Keepalived采用VRRP热备份协议实现Linux服务器的多机热备功能. VRRP,虚拟路由冗余协议,是针对路由器的 ...

  3. asp.net core-项目开发中问题汇总

    无法启动进程\Program File\dotnet\dotnet.exe.进程创建失败,出现错误:系统找不到指定的文件如下图: 解放方案:1.修改系统环境变量 2.重启电脑

  4. tcl之控制流-switch

  5. laravel通过make auth实现手机号登录

    首先按照Laravel的教程,安装认证系统. php artisan make:auth php artisan migrate laravel已经安装完成认证系统,默认注册和登录都是用邮箱. 如果想 ...

  6. 1016-02-首页17-添加转发微博控件-计算转发配图的 Frame-------打印出 被转发微博的模型

    说明:HWStatus为微博模型,_retweeted_status 为返回的数据( 一条微博模型)里面的一个属性,_retweeted_status 不为空表示此微博是否转发了其他微博._retwe ...

  7. Reward HDU - 2647

    传送门     Dandelion's uncle is a boss of a factory. As the spring festival is coming , he wants to dis ...

  8. POJ:1258-Agri-Net

    Agri-Net Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 65322 Accepted: 27029 Descriptio ...

  9. 笔记-python-多线程-深入-1

    笔记-python-多线程-深入-1 1.      线程池 1.1.    线程池:控制同时存在的线程数量 threading没有线程池,只能自己控制线程数量. 基本有两种方式: 每间隔一段时间创建 ...

  10. SpringMVC---其它常用注解

    常用注解 PathVariable @RequestMapping注解中使用占位符的情况下,需要使用@PathVariable注解指定占位符参数.即指定占位符中的值与方法中哪一个参数进行匹配.如果方法 ...