Phone List HDU - 1671 字典树
题意:给出一堆一组一组的数字 判断有没有哪一个是另外一个的前缀
思路:字典树 插入的同时进行判断 不过 当处理一组数字的时候 需要考虑的有两点1.是否包含了其他的序列2.是否被其他序列包含
刚开始开的1e4死活不过 1e5直接过了。。
#include<bits/stdc++.h>
#include<string>
using namespace std;
const int maxn=1e5+;
struct Trie{
int size;
int ch[maxn][];
int isEnd[maxn];
void init(){
memset(ch,,sizeof(ch));
memset(isEnd,,sizeof(isEnd));
size=;
}
bool insert(char*s){
int rc=,i=;
int flag=;
for(;s[i]!='\0';i++){
int id=s[i]-'';
if(ch[rc][id]==){
ch[rc][id]=size++;
flag=;
}
if(isEnd[rc]==)return ;
rc=ch[rc][id];
//if(isEnd[rc]==1)return 1; }
isEnd[rc]=;
return flag;
}
}trie;
char s[];
int main(){
int t;
scanf("%d",&t);
while(t--){
int ok=;
int n;
scanf("%d",&n);
trie.init();
for(int i=;i<n;i++){
scanf("%s",s);
if(ok)continue;
if(trie.insert(s))ok=;
}
if(ok)printf("NO\n");
else printf("YES\n");
}
return ;
}
Phone List HDU - 1671 字典树的更多相关文章
- hdu 1671(字典树判断前缀)
Phone List Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 5687 字典树插入查找删除
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5687 2016百度之星资格赛C题,直接套用字典树,顺便巩固了一下自己对字典树的理解 #include< ...
- HDU 5384 字典树、AC自动机
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5384 用字典树.AC自动机两种做法都可以做 #include<stdio.h> #includ ...
- hdu 2112(字典树+最短路)
HDU Today Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 2072(字典树模板,set,map均可做)
地址:http://acm.hdu.edu.cn/showproblem.php?pid=2072 lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词 ...
- Chip Factory HDU - 5536 字典树(删除节点|增加节点)
题意: t组样例,对于每一组样例第一行输入一个n,下面在输入n个数 你需要从这n个数里面找出来三个数(设为x,y,z),找出来(x+y)^z(同样也可以(y+z)^1)的最大值 ("^&qu ...
- hdu 1251 字典树的应用
这道题看了大神的模板,直接用字典树提交的会爆内存,用stl 里的map有简单有快 #include <iostream> #include <map> #include < ...
- hdu 2896 字典树解法
#include <iostream> #include <cstring> #include <cstdio> #include <cstdlib> ...
- Repository HDU - 2846 字典树
题意:给出很多很多很多很多个 单词 类似搜索引擎一下 输入一个单词 判断有一个字符串包含这个单词 思路:字典树变体,把每个单词的后缀都扔字典树里面,这里要注意dd是一个单词 但是把d 和dd都放字典树 ...
随机推荐
- [C#] LINQ之SelectMany
声明:本文为www.cnc6.cn原创,转载时请注明出处,谢谢! 一.第一种用法: public static IEnumerable<TResult> SelectMany<TSo ...
- 四、xadmin自定义插件1
插件原理: Xadmin中每个页面都是一个AdminView对象返回的HTTPResponse结果. Xdamin插件所做的事情就是其实就是在AdminView执行过程中改变其执行逻辑或是改变其返回的 ...
- H5 类选择器
10-类选择器 错误的写法: --> 迟到毁一生 早退穷三代 按时上下班 必成高富帅 我是段落 我是段落 <!DOCTYPE html> <html lang="en ...
- long double
long double 输入输出 scanf("%Lf",&a); printf("%.20Lf\n",a);
- js总结:onClick=“return confirm()”实现确认以及取消表单的提交
- 阿里云CodePipeline vs Jenkins
产品概述_产品简介_CodePipeline-阿里云 https://help.aliyun.com/document_detail/56512.html CodePipeline管理控制台https ...
- gethostbyname用法
//会优先查询解析%windir%\system32\drivers\etc\hosts中静态dns表 //一个域名可对应多个IP hostent->h_addr_list ==> 是in ...
- Jquery 选择器 特殊字符 转义字符
1.Jquery 选择器 id包含特殊字符,加双斜线 \\ 例 <input type="text" id="dbo_HouseInfo.HouseResour ...
- VS2015 + OPENCV + CUDA 安装流程
VS2015 https://blog.csdn.net/guxiaonuan/article/details/73775519?locationNum=2&fps=1 OPENCV htt ...
- [转帖]Introduction to text manipulation on UNIX-based systems
Introduction to text manipulation on UNIX-based systems https://www.ibm.com/developerworks/aix/libra ...