hdu 1671 Phone List 统计前缀次数
Phone List
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 27948 Accepted Submission(s): 9204
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.
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.
#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 统计前缀次数的更多相关文章
- hdu 1671(字典树判断前缀)
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 ...
- hdu 1671 Phone List 字典树
// hdu 1671 Phone List 字典树 // // 题目大意: // // 有一些电话号码的字符串长度最多是10,问是否存在字符串是其它字符串的前缀 // // // 解题思路: // ...
- Java web--Filter过滤器分IP统计访问次数
分IP统计访问次数即网站统计每个IP地址访问本网站的次数. 分析 因为一个网站可能有多个页面,无论哪个页面被访问,都要统计访问次数,所以使用过滤器最为方便. 因为需要分IP统计,所以可以在过滤器中创建 ...
- awk 统计出现次数--转
知识点: 1)数组 数组是用来存储一系列值的变量,可通过索引来访问数组的值. Awk中数组称为关联数组,因为它的下标(索引)可以是数字也可以是字符串. 下标通常称为键,数组元素的键和值存储在Awk程序 ...
- PHP+Mysql统计文件下载次数实例
PHP+Mysql统计文件下载次数实例,实现的原理也很简单,是通过前台点击链接download.php传参id,来更新点击次数. 获取文件列表: <?php require 'conn.php' ...
- Java实现 蓝桥杯VIP 算法训练 统计字符次数
算法训练 统计字符次数 时间限制:1.0s 内存限制:512.0MB 输入一个字符串(长度在100以内),统计其中数字字符出现的次数. 样例输入 Ab100cd200 样例输出 6 import ja ...
- JavaScript判断字符串中出现次数最多的字符,并统计其次数
要求: 输出一个给定字符串``中出现次数最多的字符,并统计其次数. 实现思路: 利用charA()遍历这个字符串 把每个字符都存储给对象,如果对象没有该属性,就先幅值为1,如果存在了就+1 遍历对象, ...
- HDU 1671 (字典树统计是否有前缀)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1671 Problem Description Given a list of phone number ...
随机推荐
- Mybatis框架模糊查询
一.ISmbmsUserDao层 //根据姓名模糊查询 public List<Smbms> getUser(); //多条件查询 public List<Smbms> get ...
- ionic3记录之APP运行时网络判断
判断设备网路是否正常: 安装插件: ionic cordova plugin add cordova-plugin-network-information npm install --save@nat ...
- 解题报告:SP1043 GSS1
题目链接:SP1043 GSS1 - Can you answer these queries I 对,\(GSS\)毒瘤数据结构题,就是我在这篇文章中提到的紫题. 相对其他\(GSS\)题简单些,但 ...
- 085、Java数组之实现排序
01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...
- 关闭Hyper-V后,天翼校园宽带(Netkeeper)依旧显示Sorry, this application cannot run under a Virtual Machin的解决方法
环境: win10专业版,版本1909 经过: 尝试了一下win10 更新后的沙盒系统,当时开启了沙盒,但是未打开Hyper-V,沙盒正常运行. 第二次开机后天翼校园宽带(Netkeeper)显示So ...
- 【Unity】稍微说一下关于各种坐标的转换。比如WorldToScreenPoint
之前写了一篇关于在物体头顶上显示名字的随笔. 估计难懂的点就在各种坐标的转换. 这里详细(就我这水平,怎么可能详细~~~)解说一下.额............. 用另一种方式举个栗子吧. 还是实现在物 ...
- mysql explain参数解析
建表语句 -- ---------------------------- -- Records of departments -- ---------------------------- INSER ...
- SciPy 安装
章节 SciPy 介绍 SciPy 安装 SciPy 基础功能 SciPy 特殊函数 SciPy k均值聚类 SciPy 常量 SciPy fftpack(傅里叶变换) SciPy 积分 SciPy ...
- HihoCoder第二周与POJ3630:Trie树的建立
这又是两道一样的题,都是建立trie树的过程. HihoCoder第二周: 这里其实逻辑都很简单,主要在于数据结构struct的使用. #include <iostream> #inclu ...
- 解决使用还原卡的PC在2个月后要重新加入域的问题
客户端正确操作: 1. 启动注册表编辑器. 要这样做, 请依次单击 开始 . 运行 , 类型 regedit 在 打开, 框, 然后单击 确定 . 2. 找到并单击以下注册表子项: HKEY_LOCA ...