博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU-1671 Phone List
阅读量:4691 次
发布时间:2019-06-09

本文共 1308 字,大约阅读时间需要 4 分钟。

链接:

题意给定n个字符串,问是否有字符串是其他字符串的前缀

思路字典树裸题,我套板子的

代码:

1 //#include
2 #include
3 #include
4 #include
5 #define inf 0x3f3f3f3f 6 using namespace std; 7 typedef long long ll; 8 typedef long double ld; 9 const int M = int(1e5)*2 + 5;10 const int mod = 10056;11 inline int lowbit(int x) {12 return x & (-x);13 }14 15 char s[M];16 int trie[M][15],cnt[M];17 bool f;18 int tot;19 void insert(){20 int root=0;21 for(int i=0;s[i];i++){22 int id=s[i]-'0';23 if(trie[root][id]==0){24 trie[root][id]=tot++;25 }26 root=trie[root][id]; 27 }28 cnt[root]++;29 }30 void search()31 {32 int root=0;//从根结点开始找33 for(int i=0;s[i];i++)34 {35 int x=s[i]-'0';//36 if(trie[root][x]==0) return;//以root为头结点的x字母不存在,返回0 37 if(cnt[trie[root][x]]!=0){38 f=1;39 return;40 }41 root=trie[root][x];//为查询下个字母做准备,往下走 42 }43 f=1;//找到了44 }45 46 int main()47 {48 int n;cin>>n;49 while(n--){50 memset(trie,0,sizeof(trie));51 memset(cnt,0,sizeof(cnt));52 tot=1;f=0;53 int m;cin>>m;54 for(int i=0;i

备注其实字典树我还不会写呢

 

转载于:https://www.cnblogs.com/harutomimori/p/11288100.html

你可能感兴趣的文章
Entity Framework 学习高级篇1—改善EF代码的方法(上)
查看>>
Mybatis逆向工程配置文件详细介绍(转)
查看>>
String类的深入学习与理解
查看>>
不把DB放进容器的理由
查看>>
OnePage收集
查看>>
Java parseInt()方法
查看>>
yahoo的30条优化规则
查看>>
[CCF2015.09]题解
查看>>
[NYIST15]括号匹配(二)(区间dp)
查看>>
json_value.cpp : fatal error C1083: 无法打开编译器生成的文件:No such file or directory
查看>>
洛谷 P1101 单词方阵
查看>>
Swift DispatchQueue
查看>>
C#和JAVA 访问修饰符
查看>>
小甲鱼OD学习第1讲
查看>>
HDU-1085 Holding Bin-Laden Captive-母函数
查看>>
php提示undefined index的几种解决方法
查看>>
LRJ
查看>>
Struts2环境搭建
查看>>
Linux: Check version info
查看>>
Javascript-正则表达式-开发中的使用.
查看>>