Phone List

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

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
 
题意:判断电话号码是不是其它电话号码的前缀,是输出YES,否则输出NO
 
注意开数组的大小100050
#include<iostream>
#include<string>
#include<string.h>
using namespace std;
int vis[],tree[][];
int root,id,len,n,t,i,num,flag;
string s[]; void insert()
{
root=;
len=s[i].length();
for(int j=;j<len;j++)
{
id=s[i][j]-'a';
if(!tree[root][id])
tree[root][id]=++num;
vis[tree[root][id]]++;
root=tree[root][id];
}
} int search(string ss)
{
root=;
len=ss.length();
for(int j=;j<len;j++)
{
id=ss[j]-'a';
if(!tree[root][id])
return ;
root=tree[root][id];
}
return vis[root];
}
int main()
{
cin>>t;
while(t--)
{
flag=,num=,i=;
memset(tree,,sizeof(tree));
memset(vis,,sizeof(vis));
cin>>n;
for(i=;i<n;i++)
{
cin>>s[i];
insert();
}
for(int j=;j<n;j++)
{
if(search(s[j])!=)
{
flag=;
cout<<"NO"<<endl;
break;
}
}
if(flag==)
cout<<"YES"<<endl; }
return ;
}

hdu 1671 Phone List 统计前缀次数的更多相关文章

  1. hdu 1671(字典树判断前缀)

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

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

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

  3. hdu 1671 Phone List 字典树

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

  4. Java web--Filter过滤器分IP统计访问次数

    分IP统计访问次数即网站统计每个IP地址访问本网站的次数. 分析 因为一个网站可能有多个页面,无论哪个页面被访问,都要统计访问次数,所以使用过滤器最为方便. 因为需要分IP统计,所以可以在过滤器中创建 ...

  5. awk 统计出现次数--转

    知识点: 1)数组 数组是用来存储一系列值的变量,可通过索引来访问数组的值. Awk中数组称为关联数组,因为它的下标(索引)可以是数字也可以是字符串. 下标通常称为键,数组元素的键和值存储在Awk程序 ...

  6. PHP+Mysql统计文件下载次数实例

    PHP+Mysql统计文件下载次数实例,实现的原理也很简单,是通过前台点击链接download.php传参id,来更新点击次数. 获取文件列表: <?php require 'conn.php' ...

  7. Java实现 蓝桥杯VIP 算法训练 统计字符次数

    算法训练 统计字符次数 时间限制:1.0s 内存限制:512.0MB 输入一个字符串(长度在100以内),统计其中数字字符出现的次数. 样例输入 Ab100cd200 样例输出 6 import ja ...

  8. JavaScript判断字符串中出现次数最多的字符,并统计其次数

    要求: 输出一个给定字符串``中出现次数最多的字符,并统计其次数. 实现思路: 利用charA()遍历这个字符串 把每个字符都存储给对象,如果对象没有该属性,就先幅值为1,如果存在了就+1 遍历对象, ...

  9. HDU 1671 (字典树统计是否有前缀)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1671 Problem Description Given a list of phone number ...

随机推荐

  1. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 按钮:制作一个大按钮

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  2. hdu 2838 Cow Sorting 树状数组求所有比x小的数的个数

    Cow Sorting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. ionic3记录之栅格布局使文字居中

    { display:flex; align-items:center; } 未完待续...

  4. Ubuntu18.04--双显卡Nvida笔记本安装之各种问题

    (1)安装   出现卡logo或者黑屏 关机重启,按住esc键或shift键不放,进入选择模式,按F6进入选择,nomodeset模式 (2)循环的登陆,或者安装好后重启无法再次进入系统 关机重启,在 ...

  5. 回顾PHP:第一章:PHP基础语法

    第一章:PHP基础语法 一.常量: 1.1.define()函数:define(‘R’,’5’,’true’); //R:常量名,5:常量值,true:常量名对大小写不敏感,为false时表示对常量名 ...

  6. [经验] 使用 jQuery+JSON 实现国际化

    技术选型关键词:  [spring boot] [jQuery] [JSON] [JSP] 前言: 关于国际化, 我在一开始的时候就有一个误解, 我认为所谓国际化就是编写一段高技术含量的代码, 然后这 ...

  7. 067、Java面向对象之不实例化对象报错

    01.代码如下: package TIANPAN; class Book { // 定义一个新的类 String title; // 书的名字 double price; // 书的价格 public ...

  8. Unity3D渲染优化技巧

    优化图形性能 良好的性能对大部分游戏的成功具有决定作用.下面是一些简单的指导,用来最大限度地提高游戏的图形渲染. 图形需要哪些开销 游戏的图形部分主要开销来自电脑的两个系统: GPU 或 CPU.优化 ...

  9. 吴裕雄--天生自然JAVA面向对象高级编程学习笔记:final关键字

    final class A{ // 使用final定义类,不能有子类 }; class B extends A{ // 错误,不能被继承 }; class A{ public final void p ...

  10. 站在巨人的肩膀上才能看得更加远[Amo]

    本来只是路过,写详细一点. 我看楼主浮躁得不得了.现在什么都不要做了,先去看几遍<不要做浮躁的嵌入式工程师>这篇文章,想清楚了,再动手吧. 我做了个实例,不用ST的库来点LED,解答你的问 ...