openjudge 4089:电话号码 字典树
来源:互联网 发布:校园网mac地址克隆 编辑:程序博客网 时间:2024/06/06 17:56
很明显是一道裸的字典树,但是好久不刷,我忘了。。。
这种情况还是在看一下比较好。
大概看了下,自己写的,插入的时候直接查找,找到就return0
#include <iostream>#include <queue>#include <iomanip>#include <vector>#include <queue>#include <map>#include <stack>#include <cstdio>#include <algorithm>#include <cmath>#include <set>#include <sstream>#include <cstring>using namespace std;struct trie{ int ch[100001][11]; int val[100001]; int sz; void init() { sz=0; memset(ch,0,sizeof(ch)); memset(val,0,sizeof(val)); } int insert_str(string str) { int u=0; for(int i=0;i<str.size();i++) { int index=str[i]-'0'; if(!ch[u][index]) { ch[u][index]=++sz; memset(ch[sz],0,sizeof(ch[sz])); } else { if(val[ch[u][index]]) return 0; if(i==str.size()-1) return 0; } u=ch[u][index]; } val[u]=1; return 1; }};trie T;int main(){ int t; cin>>t; for(int i=1;i<=t;i++) { int n; cin>>n; T.init(); string str; vector<string> V; for(int j=1;j<=n;j++) { cin>>str; V.push_back(str); } int flag=0; for(int j=0;j<V.size();j++) { if(T.insert_str(V[j])==0) { flag=1; break; } } if(flag) cout<<"NO"<<endl; else cout<<"YES"<<endl; } return 0;}
阅读全文
0 0
- openjudge 4089:电话号码 字典树
- OpenJudge - 1002:方便记忆的电话号码
- 4089:电话号码
- 一个字典树问题--电话号码转化问题(POJ 1002 487-3279)
- 百练 4089 电话号码 -- 树的应用
- openjudge树的转换
- OpenJudge Huffman编码树
- openjudge 文本二叉树
- openjudge 二叉搜索树
- 【openjudge】二叉树
- openjudge 二叉树
- 【Openjudge】文本二叉树
- 【Openjudge】重建二叉树
- OpenJudge
- poj 4089:电话号码
- 电话号码 【trie树】
- 电话号码
- 电话号码
- Dubbo搭建:关于pom中无法找到jms等错误,找不到运行主类main()等的问题:
- Codeforces GYM 100960B: ForceField 题解
- 属于RecyclerView的万能适配器Adapter和ViewHolder
- 正则表达式
- Cortex-M3内核简析
- openjudge 4089:电话号码 字典树
- java中的单例设计模式详解
- 网络端口的分类
- 之前的博客写满了,搬家到这里
- 冒泡排序
- (27)Dubbo的Provider和consumer(springmvc)搭建完成-goodjob!
- xposed模块开发步骤总结
- hihoCoder挑战赛29 D.不上升序列
- spring boot之多环境配置