POJ3630:Phone List——题解
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——题解的更多相关文章
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
- 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解
题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...
- 2016ACM青岛区域赛题解
A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- poj1399 hoj1037 Direct Visibility 题解 (宽搜)
http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...
- 网络流n题 题解
学会了网络流,就经常闲的没事儿刷网络流--于是乎来一发题解. 1. COGS2093 花园的守护之神 题意:给定一个带权无向图,问至少删除多少条边才能使得s-t最短路的长度变长. 用Dijkstra或 ...
- CF100965C题解..
求方程 \[ \begin{array}\\ \sum_{i=1}^n x_i & \equiv & a_1 \pmod{p} \\ \sum_{i=1}^n x_i^2 & ...
随机推荐
- 安卓app连接CC2541-手机休眠后唤醒,通信不再成功
1. 现在遇到的问题,手机进入休眠状态后唤醒,APP软件和CC2541的通信不正常了,但是CC2541依然检测到时连接状态.如何解决这个问题?手机唤醒之后会重新创建活动? 2.Wakelock 锁机制 ...
- java对于Redis中jedis的操作
package com.answer.redis; import java.util.HashMap; import java.util.List; import java.util.Map; imp ...
- MVC下的Area区域知识点
新建area区域 1.如果与根目录下的url相同,那么需要在RouteConfig.cs中 public static void RegisterRoutes(RouteCollection rout ...
- uvaoj455Periodic Strings(枚举)
A character string is said to have period k if it can be formed by concatenating one or more repetit ...
- linux部署MantisBT(三)部署MantisBT
三.部署MantisBT 1.下载MantisBT https://www.mantisbt.org/download.php 2.将MantisBT安装包放在/apache/htdocs下并重命名为 ...
- Linux命令应用大词典-第37章 Linux系统故障排错
37.1 mkbootdisk:创建用于运行系统的独立启动软盘 37.2 chroot:切换根目录环境 37.3 badblocks:搜索设备的坏块 37.4 mkinitrd:创建要载入ramdis ...
- 微信小程序之基础案例详细解释
这是案例的初始页面 首先关于这个案例上面的app.json做一个特别详细的解释 首先提醒一下.json文件不能有注释,因此如果要复制的话,请把注释删去 //关于app.json详细学习 { //pag ...
- (Python爬虫04)了解通用爬虫和聚焦爬虫,还是理论知识.快速入门可以略过的
如果现在的你返回N年前去重新学习一门技能,你会咋做? 我会这么干: ...哦,原来这个本事学完可以成为恋爱大神啊, 我要掌握精髓需要这么几个要点一二三四..... 具体的学习步骤是这样的一二三.... ...
- react项目总结
1.基本框架 1.react+react-router4+redux3.7.2 2.css预编译使用sass 3.数据请求使用axios(原本是使用fetch,结果在ios10下报错) 4.ui组件库 ...
- Python全栈 项目(电子词典、协程、pdb调试)
后面我就不截图了 大家还是看原文吧 https://yq.aliyun.com/articles/629534 . ................. ...