Phone List HDU1671
字典树的包含与不包含关系
#include<bits/stdc++.h>
using namespace std;
int trie[][];
int sum[];
int pos=; bool insert1( char *word )
{
int root=;
for(int i=;i<strlen(word);i++)
{ int ch=word[i]-'';
if(trie[root][ ch ]==)
trie[root][ ch ]=++pos;
if(sum[root]==&&root!=)return false;
sum[root]=;
root=trie[root][ch]; }
if(sum[root]!=) sum[root]=;
else return false;
return true;
} int main()
{
int cas;scanf("%d",&cas);
while(cas--)
{
pos=;
int n;
memset(sum,false,sizeof(sum));
memset(trie,,sizeof(trie));
char word[];
scanf("%d",&n);
int ok=;
while(n--)
{
scanf("%s",word);
if(ok==)continue;
if(!insert1(word)){ok=;} }
if(ok)printf("YES\n");
else printf("NO\n"); } }
Phone List HDU1671的更多相关文章
- Trie的C++实现及HDU1251,hdu1671
#include<iostream> #include<cstdio> #include<string> #include<cstring> #incl ...
- 3道入门字典树例题,以及模板【HDU1251/HDU1305/HDU1671】
HDU1251:http://acm.hdu.edu.cn/showproblem.php?pid=1251 题目大意:求得以该字符串为前缀的数目,注意输入格式就行了. #include<std ...
- HDU1671——前缀树的一点感触
题目http://acm.hdu.edu.cn/showproblem.php?pid=1671 题目本身不难,一棵前缀树OK,但是前两次提交都没有成功. 第一次Memory Limit Exceed ...
- HDU1671 字典树
Phone List Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu----(1671)Phone List(Trie带标签)
Phone List Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU1671 - Phone List(Trie树)
题目大意 给定一些电话号码,判断是否有电话号码是其他电话号码的前缀 题解 裸Trie树嘛~~~~只需要一个插入过程即可,假设X是Y的前缀,在插入的过程中有两种情况,X在Y之前插入,那么在插入Y的时候经 ...
- hdu1671字典树
Phone List Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU1671 Phone List
Phone List Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Probl ...
- HDU1671 水题字典树
#include<cstdio> #include<cstdlib> #include<iostream> #include<cstring> #inc ...
随机推荐
- 第16月第5天 performSelector afterDelay cancel dispatch_semaphore_wait
1. //不延时,可能会导致界面黑屏并卡住一会 [self performSelector:@selector(startScan) withObject:nil afterDelay:0.3]; - ...
- 7、完整版的strcpy函数
char * strcpy( char *strDest, const char *strSrc ) { assert( (strDest != NULL) && (strSrc != ...
- 5、利用两个栈实现队列,完成push和pop操作
题目描述 用两个栈来实现一个队列,完成队列的Push和Pop操作. 队列中的元素为int类型. 思路: 1.一个栈用来做push 2.另一个栈用来做pop 3.将push操作的栈的元素放入另一个栈中, ...
- Freemarker取list集合中数据(将模板填充数据后写到客户端HTML)
1.模板写法: <html> <head> <title>freemarker测试</title> </head> <body> ...
- ubuntu 14.04 软件中心闪退解决方案
法一: gksudo gedit /usr/share/software-center/softwarecenter/ui/gtk3/views/lobbyview.py 注释下面这句话(注释使用#号 ...
- 【转】Python流程控制语句
[转]Python流程控制语句 人们常说人生就是一个不断做选择题的过程:有的人没得选,只有一条路能走:有的人好一点,可以二选一:有些能力好或者家境好的人,可以有更多的选择:还有一些人在人生的迷茫期会在 ...
- FarBox--另类有趣的网站服务【转】
FarBox--另类有趣的网站服务 转自:http://mosir.org/html/y2012/the-interesting-web-service-serve-by-FarBox.html 作者 ...
- 编码实现字符串类CNString实现运算符重载
题目描述: 编码实现字符串类CNString,该类有默认构造函数.类的拷贝函数.类的析构函数及运算符重载,需实现以下"="运算符."+"运算."[]& ...
- 转载:JAVA序列化与反序列化 (作者:YSOcean)
原文:https://www.cnblogs.com/ysocean/p/6870069.html File 类的介绍:http://www.cnblogs.com/ysocean/p/6851878 ...
- Android Menu用法全面讲解
说明:本文只介绍Android3.0及以上的Menu知识点. 菜单的分类 菜单是Android应用中非常重要且常见的组成部分,主要可以分为三类:选项菜单.上下文菜单/上下文操作模式以及弹出菜单.它们的 ...