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

简单的trie树问题,先添加,然后每个跑一边看中途有没有被打上结束标记即可。

#include<cstdio>
#include<cstring>
using namespace std;
struct node{
bool ed;
int son[];
void clear(){
memset(son,,sizeof(son));
ed=;
}
}tree[];
char s[][];
int tot;
void insert(int k){
int l=strlen(s[k]);
int now=;
for(int i=;i<l;i++){
if(tree[now].son[s[k][i]-'']==){
tot++;
tree[now].son[s[k][i]-'']=tot;
}
now=tree[now].son[s[k][i]-''];
}
tree[now].ed=;
return;
}
bool check(int k){
int l=strlen(s[k]);
int now=;
for(int i=;i<l;i++){
if(tree[now].son[s[k][i]-'']==){
return ;
}
if(tree[now].ed)return ;
now=tree[now].son[s[k][i]-''];
}
return ;
}
int main(){
int t;
scanf("%d",&t);
while(t--){
for(int i=;i<=;i++)tree[i].clear();
tot=;
int n;bool ok=;
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%s",s[i]);
insert(i);
}
for(int i=;i<=n;i++){
if(check(i)){
ok=;
break;
}
}
if(ok==)printf("NO\n");
else printf("YES\n");
}
return ;
}

POJ3630:Phone List——题解的更多相关文章

  1. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  2. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  3. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

  4. Codeforces Round #353 (Div. 2) ABCDE 题解 python

    Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring P ...

  5. 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

    题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...

  6. 2016ACM青岛区域赛题解

    A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  7. poj1399 hoj1037 Direct Visibility 题解 (宽搜)

    http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...

  8. 网络流n题 题解

    学会了网络流,就经常闲的没事儿刷网络流--于是乎来一发题解. 1. COGS2093 花园的守护之神 题意:给定一个带权无向图,问至少删除多少条边才能使得s-t最短路的长度变长. 用Dijkstra或 ...

  9. CF100965C题解..

    求方程 \[ \begin{array}\\ \sum_{i=1}^n x_i & \equiv & a_1 \pmod{p} \\ \sum_{i=1}^n x_i^2 & ...

随机推荐

  1. HTML <head>里面的标签

    <head> 中的标签可以引用脚本.指示浏览器在哪里找到样式表.提供元信息等等. 下面这些标签可用在 head 部分:<base>, <link>, <met ...

  2. Jenkis 无法下载插件问题解决

    在新机器上安装jenkins后,安装插件报如下错误 sun.security.provider.certpath.SunCertPathBuilderException: unable to find ...

  3. Java应用基础微专业-工程篇

    第1章-命令行 1.1 命令行基础 ls -a: list all files (including hidden files) .DS_Store: files detailed informati ...

  4. ES6 之 let / const

    本博文配合 阮一峰 <ES6 标准入门(第3版)>一书进行简要概述 ES6 中的 let 与 const. 历史遗留问题 由于 JS ES3语法中的 var 提升变量.没有块级作用域,因而 ...

  5. @meida 媒体查询

    示例 @meida 媒体查询 在进行书写的时候需要考虑到加载顺序和样式权重使用meida响应式实现不同宽度布局示例 常用工具 https://mydevice.io 参考链接 https://deve ...

  6. vim常用命令—撤销与反撤销

    命令模式下(即按ESC后的模式) u 撤销 Ctrl r (组合键) 反撤销<后悔撤销>

  7. Educational Codeforces Round 32 Problem 888C - K-Dominant Character

    1) Link to the problem: http://codeforces.com/contest/888/problem/C 2) Description: You are given a ...

  8. Nodejs基础之redis

    安装redis 模块 npm install redis 1 代码部分 const redis = require('redis') const client = redis.createClient ...

  9. POJ 1739 Tony's Tour(插头DP)

    Description A square township has been divided up into n*m(n rows and m columns) square plots (1< ...

  10. $http.get(...).success is not a function 错误解决

    $http.get(...).success is not a function 错误解决 1.6 新版本的AngularJs中用then和catch 代替了success和error,用PRomis ...