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. 吴裕雄--天生自然MySQL学习笔记:MySQL 安装

    所有平台的 MySQL 下载地址为: MySQL 下载:https://dev.mysql.com/downloads/mysql/ 注意:安装过程我们需要通过开启管理员权限来安装,否则会由于权限不足 ...

  2. 新闻网大数据实时分析可视化系统项目——11、MySQL安装

    1.修改yum源 鉴于用国外的Yum源,速度比较慢,所以想到将国外的yum源改为国内的Yum源,这里选择使用比较多的阿里云源.具体修改方法可以参考此连接 2.在线安装mysql 通过yum在线mysq ...

  3. js保留两位小数的数字格式化方法

    // 格式化数字(保留两位小数) numberFormat (num) { let percent = Number(num.toString().match(/^\d+(?:\.\d{0,2})?/ ...

  4. sdfsdsf

    1 $('.advert-title').each(function(){ 2 var TXTlength = $(this).text().length; // 当前文本的长度 3 if(TXTle ...

  5. java学习-初级入门-面向对象⑤-类与对象-类与对象的定义和使用3

    这次我们要做一个日期类Date类 主要目的是    1.  熟悉-->构造不同参数的函数  2.善于利用已有的函数!! 题目要求: Date类要求 可设定年月日 可转换为字符串,并可指定分隔符, ...

  6. 如何确定Redis集群中各个节点的主从关系

    1.首先通过命令(以192.168.203.141为例,-c代表集群的意思) ./redis-cli -h 192.168.203.141 -p 8001 -c 2.然后在输入  cluster no ...

  7. 前端学习笔记系列一:7 在vscode中根据vue等模板生成代码

    目标:希望每次新建.vue文件后,VSCODE能够根据配置,自动生成我们想要的内容. 方法:打开VSCODE编辑器,依次选择“文件 -> 首选项 -> 用户代码片段”,此时,会弹出一个搜索 ...

  8. nosql概叙

    关系型数据库管理系统:按照预先设置的组织架构,将数据存储在物理介质上 数据之间可以做关联操作

  9. sqlserver查找断号,回收单据号

    declare @L varchar(20), @R varchar(20), @Len int, @FromNo int, @F1 intselect @L='19011', @R='', @Len ...

  10. sizeof strlen 求char*字符串的长度

    sizeof只是求变量所占的字节数,sizeof(char *) = 4字节: strlen(char*) 可以得到整个字符串的长度. 如果是数组vec,那么使用sizeof就可以得到整个数组的所占的 ...