Phone List

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10837    Accepted Submission(s): 3735

Problem Description
Given
a list of phone numbers, determine if it is consistent in the sense
that no number is the prefix of another. Let’s say the phone catalogue
listed these numbers:
1. Emergency 911
2. Alice 97 625 999
3. Bob 91 12 54 26
In
this case, it’s not possible to call Bob, because the central would
direct your call to the emergency line as soon as you had dialled the
first three digits of Bob’s phone number. So this list would not be
consistent.
 
Input
The
first line of input gives a single integer, 1 <= t <= 40, the
number of test cases. Each test case starts with n, the number of phone
numbers, on a separate line, 1 <= n <= 10000. Then follows n
lines with one unique phone number on each line. A phone number is a
sequence of at most ten digits.
 
Output
For each test case, output “YES” if the list is consistent, or “NO” otherwise.
 
Sample Input
2
3
911
97625999
91125426
5
113
12340
123440
12345
98346
 
Sample Output
NO
YES
 
Source
 
简单字典树:
代码:  实现 insert ,query,delete 三部分
 /*hdu 1671 ×ÖµäÊ÷*/
#define LOCAL
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
struct Trie
{
struct Trie *next[];
bool tail;
};
char str[][];
void in_Trie(char *s,Trie *root)
{
Trie *cur=root,*newcur;
for(int i=;s[i]!='\0';i++)
{
if(cur->next[s[i]-'']==NULL)
{
newcur=new Trie; //(Trie*)malloc(sizeof(sizeof(Trie)));
for(int j=;j<=;j++)
newcur->next[j]=NULL;
newcur->tail=;
cur->next[s[i]-'']=newcur;
}
cur=cur->next[s[i]-''];
}
cur->tail=;
}
bool query(char *s,Trie *root)
{
int i=;
Trie *cur=root;
for(i=;s[i];i++){
if(cur->tail==&&cur->next[s[i]-'']!=NULL)
cur=cur->next[s[i]-''];
else break;
}
if(s[i]!='\0') return ;
return ;
}
void dele(Trie *root)
{
for(int i= ; i<= ; i++ )
if(root->next[i]!=NULL)
dele(root->next[i]);
// free(root);
delete root;
}
int main()
{
#ifdef LOCAL
freopen("test.in","r",stdin);
#endif
int t,i,n;
Trie *root;
scanf("%d",&t);
while(t--)
{
root = new Trie ;
for(int j=;j<=;j++)
root->next[j]=NULL;
root->tail=; scanf("%d",&n);
for(i=;i<n;i++){
scanf("%s",str[i]);
in_Trie(str[i],root);
} for(i=;i<n;i++)
if(query(str[i],root)!=)
break;
dele(root);
if(i>=n)
printf("YES\n");
else
printf("NO\n");
}
return ;
}

hdu----(1671)Phone List(Trie带标签)的更多相关文章

  1. HDU 1671 Phone List (Trie·数组实现)

    链接:http://blog.csdn.net/acvay/article/details/47089657 题意  给你一组电话号码  判断其中是否有某个电话是另一个电话的前缀 字典树的基础应用   ...

  2. hdu 1671 Phone List (Trie树)

    简单的字典树应用,在建树的时候判断就行了. 需要注意的语法: 在使用malloc和free来处理动态内存的时候,仅仅是释放了这个对象所占的内存,而不会调用这个对象的析构函数:使用new和delete就 ...

  3. [hdu 1671] Phone List - Trie

    Given a list of phone numbers, determine if it is consistent in the sense that no number is the pref ...

  4. hdu 1671&& poj 3630 (trie 树应用)

    Phone List Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 25280   Accepted: 7678 Descr ...

  5. HDU 1671 Phone List(Trie的应用与内存释放)

    Phone List Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  6. hdu 1671 Phone List 字典树

    // hdu 1671 Phone List 字典树 // // 题目大意: // // 有一些电话号码的字符串长度最多是10,问是否存在字符串是其它字符串的前缀 // // // 解题思路: // ...

  7. [TFRecord格式数据]利用TFRecords存储与读取带标签的图片

    利用TFRecords存储与读取带标签的图片 原创文章,转载请注明出处~ 觉得有用的话,欢迎一起讨论相互学习~Follow Me TFRecords其实是一种二进制文件,虽然它不如其他格式好理解,但是 ...

  8. tp5.带标签的缓存 创建和清除 测试

    原文:http://www.upwqy.com/details/24.html 测试设置了标签的缓存的获取方式 和清除标签缓存. 有时候我们可能会对同类型的一些数据做统一缓存.和统一清除更新处理. 那 ...

  9. 带标签的循环语句、switch

    今天继续更新,控制流程的剩余部分内容,带标签的循环语句中的continue/break 的使用方法,以及switch关键字的使用方法.例1:带标签的continue/break.package com ...

随机推荐

  1. Atlassian如何实施DevOps

    DevOps是推动开发和运维团队之间沟通和协作的手段.它不是一个工具或产品.相反,其成功的首要因素就是文化.目的是更快的创新和更好的客户体验. "2015年DevOps状态报告"调 ...

  2. 各种操作中心Operation Center一览

    Operation Center在中国可能有很多种名称,例如指挥中心.运维室.总控中心等等,国外可能也有很多名称,不管名称如何,任何一个上规模得数据总心或者运维单位一般都有一个这样得中心,来负责所管理 ...

  3. 折半查找&clock函数

    #include <stdio.h>#include <time.h> #define CLOCKS_PER_SEC ((clock_t)1000) int binsearch ...

  4. [Java解惑]异常

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  5. Codeforces Round #243 (Div. 2) B(思维模拟题)

    http://codeforces.com/contest/426/problem/B B. Sereja and Mirroring time limit per test 1 second mem ...

  6. kakfa源代码开发环境搭建过程中的错误处理

    在window上搭建kafka的源代码开发环境,主要参考如下的blog: http://www.bubuko.com/infodetail-695974.html    << Window ...

  7. VS2012创建MVC3项目提示错误: 此模板尝试加载组件程序集 “NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”。

    如果在没有安装vs2012 update3升级包的情况下,创建MVC3项目会出现下面的错误信息. 因为VS2012已经全面切换到使用NuGet这个第三方开源工具来管理项目包和引用模块了,使用VS201 ...

  8. Scrum Meeting---Two(2015-10-26)

    这次会议主要有两个方面 一.讨论项目 经过我们团队的激烈讨论,我们团队决定专注于做二手交易这一块.即将之前决定要做的学习经验交流以及校园交由这两块删除. 二.后两天的任务规划 以下便是我们的任务规划: ...

  9. RTMP命令亲自测试记录

    手动和自动录像模块: recorder rec1 { record all manual; record_unique on; record_notify on; record_max_size 51 ...

  10. Java中正则Matcher类的matches()、lookAt()和find()的区别<转>

    在Matcher类中有matches.lookingAt和find都是匹配目标的方法,但容易混淆,整理它们的区别如下: matches:整个匹配,只有整个字符序列完全匹配成功,才返回True,否则返回 ...