HDU1671 Phone List(字典树)

[字典树 ] hdu 1671 phone list /** hdu 1671 phone list 字典树和poj3630是同一道题 */ #include #include #include #define N 100000 struct tireTree { bool isNum; tireTree *child[10]; }tt[N],*sp; struct Phone { int len; cha 阅读详情
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


题意: 看每个串的字串是否会与别的串相同,有则输出  NO, else  输出YES


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>

#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define eps 1e-8
typedef __int64 ll;

using namespace std;

#define N 10

struct node{
  bool flag;
  node *nest[N];
};

node *root;
char phone[10050][20];



void inset(char *c)
{
    node * tem=root;

    while(*c!='\0')
	{
		if(tem->nest[*c-'0']==NULL)
		{
			node * cur;
			cur=(node *)malloc(sizeof(node));

			for(int i=0;i<N;i++)
				cur->nest[i]=NULL;

			cur->flag=false;
			tem->nest[*c-'0']=cur;
		}

		tem=tem->nest[*c-'0'];
		c++;
	}
	tem->flag=true;
}



int seach(char *c)
{
	int i,j;
	node * temp=root;
	
	while(*c!='\0')
	{
		if(temp==NULL||temp->nest[*c-'0']==NULL)
			return 0;

		temp=temp->nest[*c-'0'];
		c++;
	}
	return temp->flag;
}

void delet(node* temp)
{
	if(temp==NULL) return ;

	for(int i=0;i<N;i++)
		if(temp->nest[i]!=NULL)
		 delet(temp->nest[i]);
		 
	free(temp);
}

void inint()
{
	int i,j;
	
	root=(node *) malloc(sizeof(node));
	root->flag=false;

	for(i=0;i<N;i++)
		root->nest[i]=NULL;

}

int main()
{
   int i,j,t,n;
   scanf("%d",&t);
   
   while(t--)
   {
   	  inint();
   	  scanf("%d",&n);
   	  for(i=0;i<n;i++)
		{
			scanf("%s",phone[i]);
			inset(phone[i]);
		}

	    int flag=1;
	    char c[20];

	    for(i=0;i<n;i++)
		{
			if(!flag) break;
		   int len=strlen(phone[i]);
		   
		   memset(c,'\0',sizeof(c));
		

		   for(j=0;j<len-1;j++)
			{
			 c[j]=phone[i][j];
			 
		     if(seach(c))
			 {
			 	flag=0;
			 	break;
			 }
			}
		}

		if(flag)
			printf("YES\n");
		else
			printf("NO\n");

	  delet(root);
   }
   return 0;

}








Multisim14安装失败?手把手教你彻底清理残留文件(附专用卸载工具) 本文针对Multisim14安装失败问题,提供了一套从根源解决的完整方案。文章详细分析了安装失败的三大元凶——文件残留、注册表残留和隐藏组件,并手把手指导用户使用专用卸载工具进行标准化清理,再结合手动深度清理文件系统和注册表,最终实现彻底卸载和完美重装,有效解决Multisim14安装问题。 阅读详情

相关推荐

从Si3N4到SiNx:一文搞懂芯片制造中氮化硅的化学式玄机(附工艺参数影响)

本文深入探讨了芯片制造中氮化硅(SiNx)化学式的调控艺术,揭示了从Si3N4到SiNx的转变如何影响材料性能。通过分析PECVD和PVD工艺参数对x值的精确调控,以及x值对电学和机械性能的影响,为半导体制造提供了实用的工艺优化策略。

weixin_30776273的博客 192

字典树 Phone List

Phone List 题目描述 给定 个长度不超过 的数字串,问其中是否存在两个数字串 ,使得 是 的前缀,多组数据。 输入格式 第一行一个整数 ,表示数据组数。 对于每组数据,第一行一个数 ,接下来 行输入 个数字串。 输出格式 对于每组数据,若存在两个数字串 ,,使得 是 的前缀,则输出 NO ,否则输出 YES 。 请注意此处结果与输出的对应关系! 样例 样例输入 2 3 911 97625999 91125426 5 113 12340 123440 12345 98346 样例输出

nearal的博客 431

modelsim软件安装教程及踩坑(极简版)

1.安装的网盘链接:链接:https://pan.baidu.com/s/1ltUfssyXlCnqDmLhWyhlwA提取码:jery 2.步骤(参考博文):https://blog.youkuaiyun.com/weixin_42693097/article/details/90523692?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522163521788716780357213801%2522%252C%2522scm%2522%253A%2522

subtitle_的博客 3780

Phone List(简单字典树或暴力)

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: Emergency 911 Alic...

PleasantlY1的博客 3789

SAP-MM-PR分配货源并转PO

SAP-MM-PR分配货源并转PO

yanzibing99的博客 5473

PLc S7-200 smart如何使用Modbus 485通讯传输接收数据

西门子在 STEP 7-Micro/WIN SMART 中正式推出 Modbus RTU 主站协议库(西门子标准库指令)。使用 Modbus RTU 主站指令库,可以读写 Modbus RTU 从站的数字量、模拟量 I/O 以及保持寄存器,从而实现PLC通过modbus方式控制其他器件。提示:以下是本篇文章正文内容,下面案例可供参考。

xjbsw0的博客 6万+

Phone List(字典树,数据结构)

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

geguojun 的专栏 879

Cadence SIP Layout 简单教程-第一章

以摄像头模组软硬结合板为例,描述layout的整个完整过程,从而掌握基本技能。 第一章 准备工作 第一节 原理图不用说layout前需要绘制原理图,原理图不在本文讨论范围内,所以列为准备工作。 需要特别说明的是,绘制原理的最终目的是导出网络表,网络表中的重要参数footprint是让layout软件选择正确封装的关键,所以这里讲解一下原理图设置footprint的位置。在原理图中双击零件,...

whp1920的博客 1万+

Phone List题解

题目链接 题目分析:字典树的裸题,把每个字符串读入后,插入字典树,在从头到尾便利一遍每个字符串,如果在遍历过程中遇到某个节点是另一个字符串的结尾,(注意做个标记排除自身),则输出“NO”。 代码如下: #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #in...

gyr679的博客 515

7.19华为OD机试真题 新系统 - 物流仓储多维度成本利润综合查询系统 (Java/Py/C/C++/Js/Go)

7.19华为OD机试真题 新系统 - 物流仓储多维度成本利润综合查询系统 (Java/Py/C/C++/Js/Go)

算法大师! 618

27、超声成像技术与原理全面解析

本博客全面解析了超声成像技术与原理,涵盖声学材料特性、超声成像系统的基本概念与组成、关键技术如多普勒和聚焦技术、超声换能器的设计与原理、图像处理方法、系统校准与质量控制,以及超声成像的应用领域和发展趋势。旨在为医学诊断、工业检测和海洋声学等领域的研究人员和工程师提供深入的技术参考和指导。

z2a3b4c5d的博客 494

Phone List (排序+字典树)

Phone List (排序+字典树) 题目大意:给出多组字符串,问是否有某一个字符串是另一个字符串的前缀,有的话输出NO,没有 输出YES。 解题思路:把字符串按照长度从大到小排序一下,然后插入,看此串是否出现过。 Code: #include <iostream> #include <cstdio> #include<cmath> #include <cstring> #include <algorithm> #include <vec

林黛玉到拔垂杨柳的博客 627

读懂 ABAP CDS 注解的直接、继承与派生

本文系统梳理了ABAP CDS注解的评估逻辑,重点解析直接注解(Direct)、继承注解(Inherited)和派生注解(Derived)的差异及其在CL_DD_DDL_ANNOTATION_SERVICE中的处理方式。通过视图注解@Metadata.ignorePropagatedAnnotations可调控注解传播行为,避免下游语义影响上层视图。文章还提供了基于标准表的完整示例(包含底层视图、消费视图和ABAP报告程序),帮助开发者在实际系统中验证三层注解的叠加效果与阻断机制。关键点包括:派生注解的数据

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 245

HDU 1671 Phone List(字典树Trie)

HDU 1671 Phone List(字典树Trie) http://acm.hdu.edu.cn/showproblem.php?pid=1671 题意:给你多个由0-9构成的字符串集合,问你这个集合中是否有一个字符串是其他字符串的前缀? 分析:直接构造字典树,然后一一插入每个字符串,判断是否有比当前字符串短或长的同一路径的字符串已经在树中了.        注意:字典树中如果该节点是

code 1306

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

【字典树】 hdu1671 Phone List

Phone List http://acm.hdu.edu.cn/showproblem.php?pid=1671 Problem Description Given a list of phone numbers, determine if it is consistent in the sense that no number is the prefix of ano

Ted's 游乐园 1167

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

HDU 1671 Phone List 【字典树】

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

Joeferyの博客 432

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

【HDU 1671 --- Phone List】字典树

【HDU 1671 --- Phone List】字典树 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 n...

来日浅谈的博客 491

HDU 1671 Phone List(字典树)

- HDU 1671 - Phone List Time Limit: 3000/1000 MS (Java/Others) | Memory Limit: 32768/32768 K (Java/Others) 题意: 给定一个整数 t ,表示测试案例数,每个测试案例给定一个整数 n ,接下来输入 n 行号码,判断这些号码中是否有某个号码是另一个号码的前缀,若有,则输出‘NO’,否则,...

Pandora_heart的博客 301

hdu1671-Phone List 字典树

Phone List Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 20633    Accepted Submission(s): 6974 Problem Description Given a list o

wangheng 430

hdu 1671 Phone List 字典树

第一次写字典树 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1671 #include #include #define maxn 15 using namespace std; struct Trie{ Trie * next[maxn]; int v; }; Trie * root; int flag; vo

NM的专栏 449

Phone List 【 HDU - 1671 】 【 字典树判断是否存在前缀 】

Phone List  HDU - 1671  题意:每个字符串都必须不能是别的字符串的前缀。 题解:用字典树,然后给每个字符串的最后打上标记,每次读入一个字符串之后,先判断树里面是否有这个字符串的前缀,在判断这个字符串是否是之前的前缀。 #include &lt;bits/stdc++.h&gt; using namespace std; struct node { s...

Mercury_Lc的博客 378

Phone List HDU - 1671 字典树

题意:给出一堆一组一组的数字 判断有没有哪一个是另外一个的前缀 思路:字典树 插入的同时进行判断 不过 当处理一组数字的时候 需要考虑的有两点1.是否包含了其他的序列2.是否被其他序列包含 刚开始开的1e4死活不过 1e5直接过了。。 1 #include<bits/stdc++.h> 2 #include<string> 3 usi...

azmkinbug41973327的博客 146

HDU 1671 Phone List(字典树)

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

MengDeMao1234的博客 162

Phone List HDU - 1671(字典树)

Phone List HDU - 1671 题目链接:https://vjudge.net/problem/HDU-1671 题目: 给出一个电话号码列表,确定它是否一致,因为没有数字是另一个号码的前缀。 假设电话目录列出了这些数字:1. Emergency 911 2. Alice 97 625 999 3. Bob 91 12 54 26 在这种情况下,无法呼叫...

weixin_30633949的博客 244

hdu - problem 1671 Phone List【字典树】

Phone List Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 18382    Accepted Submission(s): 6189 Problem Description Given a list o

博客已搬迁到http://www.cnblogs.com/cniwoq/ 320
上一篇: HDU 1116 Play on Words(欧拉通路)
下一篇: HDU1251 统计难题(字典树)
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值