HDU 1671 Phone List Trie Tree
来源:互联网 发布:windows nginx 自启动 编辑:程序博客网 时间:2024/06/16 18:33
http://acm.hdu.edu.cn/showproblem.php?pid=1671
判断字典中是否有某个字符串是另一个字符串的前缀,Trie Tree 解决。
#include<bits/stdc++.h>using namespace std;const int MAXN = 100000 + 7;int ch[MAXN][26];int val[MAXN];int sz = 1;bool flag = false;void insert_str(string str) { int u = 0, c, tag = 0; for(int i = 0; str[i]; ++i) { c = str[i] - '0'; if(!ch[u][c]) { ch[u][c] = sz++; tag++; } else if(val[ch[u][c]] != 0) { flag = true; } u = ch[u][c]; } if(!tag) flag = true; val[u]++;}bool query_str(string str) {int u = 0, c;for(int i = 0; str[i]; ++i) { c = str[i] - '0'; if(!ch[u][c]) { return false; } u = ch[u][c];}return val[u] == 1;}int main(){ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);string str;int T;cin >> T;int n;while(T--) {flag = false;sz = 1;fill((int* )ch, (int*)ch + MAXN * 26, 0);fill(val, val + MAXN, 0);cin >> n;//bool flag = false;while(n--) {cin >> str; insert_str(str); } cout << (flag ? "NO" : "YES") << endl;}return 0;}
0 0
- HDU 1671 Phone List Trie Tree
- hdu 1671 Phone List(trie)
- HDU 1671 Phone List(Trie)
- hdu 1671 Phone List (Trie树,水题)
- hdu 1671 Phone List trie树
- HDU 1671 Phone List(字典树Trie)
- hdu 1671 Phone List(数据结构:trie)
- HDU 1671 Phone List Trie树
- Phone List - HDU 1671 Trie树
- HDU 1671 Phone List(字典树Trie)
- hdu-1671-Phone List Trie树
- HDU 1671 Phone List (Trie)
- hdu 1671 Phone List(Trie树)
- HDU 1671 Phone List trie树
- hdu 1671 Phone List Trie树
- HDU 1671 Phone List(Trie树)
- HDU 1671 Phone List(字典树Trie)
- hdu 1671 phone list Trie 树
- Palindrome subsequence
- Sum—LeetCode-415 Add Strings
- MySQL架构总览->查询执行流程->SQL解析顺序
- IntelliJ IDEA(Community版本)的下载、安装和WordCount的初步使用(本地模式和集群模式)
- Centos 7 打开端口及查询端口
- HDU 1671 Phone List Trie Tree
- linux-docker基础1
- 假设检验
- tensorflow解决问题的思路
- 简略初次操作mongo及相关命令(终端命令行)
- Android studio2.2.3 build程序后,程序运行log无变化问题
- SQL Server 维护脚本分享(13)数据库内部日常巡检
- 403错误原因和解决方法
- MPUSH消息推送服务器搭建