hdu 1671 Phone List

地震数据可视化必备:5分钟读懂SEGY道头字段全解析(含坐标定位指南) 本文深入解析了SEGY文件格式中道头坐标字段的提取与可视化方法。针对地震数据处理中的常见痛点,详细介绍了sx/sy、gx/gy等关键坐标字段的二进制解析、比例因子应用、单位转换及常见问题解决方案,并提供了实用的Python代码示例,帮助开发者实现从SEGY文件到三维空间可视化的完整流程。 阅读详情

Phone List

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

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
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1671
题目大意:给n个号码,拨通任意一个时不会打通另一个,也就是任意一个号码不是另一个的前缀。
解题思路:字典树查找判断。插入每个号码完成后,号码的最后一个数字打上标记,在插入号码过程中,如果号码还未插入完成该位置就已经做过标记,则说明该前缀已作为另一个号码存在,即不合法。如果号码在插入的整个过程中每个节点都不为空,则说明该号码已是另一个号码的前缀,即不合法。
代码如下:
#include <cstdio>
#include <cstring>
char s[10];
bool flag;
struct node 
{
    bool end;
    node *next[10];
    node()
    {
        memset(next,NULL,sizeof(next));
        end=false;
    }
};
void Insearch(node *p,char *s)
{
    int p1=0;    //判断号码插入的整个过程中节点是否有空的情况
    for(int i=0;s[i]!='\0';i++)
    {
        int a=s[i]-'0'; 
		if(p->end)flag=false;   //该位置已被标记过,说明已经有号码是该号码的子串了
        if(p->next[a]==NULL)
        {
            p->next[a]=new node();
            p1=1;
        }
        p=p->next[a];
    }
    if(!p1)flag=false; //节点没有空的情况,说明该号码已是另一个号码的前缀了
    p->end=true;    //一个号码插入完成打上标记
}
void clear(node *p)   //释放空间,这题必须!否则会超内存,递归实现
{
	for(int i=0;i<10;i++)
		if(p->next[i])
			clear(p->next[i]);
	delete p;
}
int main()
{
    int n,t;
    scanf("%d",&t);
    while(t--)
    {
        flag=true;       //判断该组号码是否合法
        scanf("%d",&n);
        node *root=new node();
        while(n--)
        {
            scanf("%s",s);
            if(!flag)continue;
            Insearch(root,s);
        }
        if(!flag)
            printf("NO\n");
        else
            printf("YES\n");
		clear(root);
    }
    return 0;
}


Data-Structures-and-Algorithm-Analysis-in-Java.pdf 作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo... 立即下载

相关推荐

Camunda流程引擎 Modeler (二)

Camunda Modeler是Camunda官方提供的建模器: 独立安装的建模器([windows、linux、mac]

1323

hdu1671-Phone List

hdu1671-Phone List

lvy的专栏 645

从原理到代码:一文搞懂LFM信号脉冲压缩在Matlab中的实现

本文深入解析了LFM信号脉冲压缩的核心原理与Matlab实现方法。从线性调频信号的数学表达、时频特性入手,详细讲解了如何构建多目标回波仿真环境,并重点阐述了匹配滤波器的频域实现算法。文章提供了完整的、可运行的Matlab代码,涵盖信号生成、噪声添加、脉冲压缩及性能评估等关键步骤,并探讨了加窗处理、参数选择等工程实践中的考量,为雷达信号处理的学习与实践提供了清晰指南。

weixin_29063035的博客 419

hdu 1671 Phone List(二叉树)

题目连接:hdu 1671 Phone List 题目大意:给出n个电话号码,判断是否存在某个电话号码是另外一个电话号码的前缀。 解题思路:建一个二叉树进行搜索时的优化。 #include #include #define min(a,b) (a)<(b)?(a):(b) const int N = 50; int n, flag; struct node

不慌不忙、不急不躁 1057

单细胞转录组数据质控实战:如何用Seurat精准过滤低质量细胞(附完整代码)

本文详细介绍了使用Seurat进行单细胞转录组数据质控的实战方法,包括基因检出数、分子计数和线粒体基因比例等关键指标的解读与可视化技巧。通过动态阈值策略和高级质控技巧(如双细胞检测和红细胞过滤),帮助研究者精准过滤低质量细胞,提升数据分析可靠性。附完整代码示例,适合生物信息学研究人员参考实践。

ii567的博客 829

ANSYS拓扑优化基础实例

唐深51CAE 2018/6/10 拓扑优化在工程设计中,常用于机械结构概念设计和轻量化设计,ANSYS通用有限元分析软件提供了强大的拓扑优化功能,本文将通过一个简单实例进行展示。 一、赵州桥 赵州桥又称安济桥,坐落在河北省赵县洨河上,建于隋朝年间公元595年~605年,由著名匠师李春设计建造,距今已有约1500年的历史,是当今世界上现存最早、保存最完整的古代敞...

TQT_CAE的博客 6031

hdu1671Phone List

普通字典树 建立普通字典树,用flag 标记,注意释放内存空间 #include #include #include #include using namespace std; typedef struct node{ int flag; struct node *next[10]; }Trie; void insertTrie(Trie *root,char *c){

梦玉的专栏 445

OPTEE常见13类问题与解答

OPTEE常见13类问题并解答

AI-安全-功耗 1209

HDU-1671-Phone List

HDU-1671-Phone List http://acm.hdu.edu.cn/showproblem.php?pid=1671 字典树,判断是否有某个数字是另一个数字的前缀,注意123不是123的前缀,建树之后要删除节点,否则会Memory LimitExceeded 写的比较麻烦,分两种情况,一是先出现123,再出现1234,;二是先出现1234,再出现123 #includ...

java开发指南博客 【转载】 160

YOLOv8 置信度阈值 (conf) 和 IoU 阈值 (iou) 详解:如何平衡漏检与误检?

摘要 本文深入探讨了YOLOv8目标检测模型中两个关键参数——置信度阈值(conf)和IoU阈值(iou)的核心作用。文章从目标检测的基础概念出发,解释了置信度分数反映模型预测可靠性,IoU衡量预测框重叠程度。重点剖析了非极大值抑制(NMS)机制如何通过这两个阈值进行预测框筛选:置信度阈值作为初筛门槛,IoU阈值决定重叠框的取舍。通过生动比喻和可视化图表,阐述了合理调节这两个参数能有效平衡误检与漏检问题,是优化YOLOv8模型实际表现的重要技巧。全文以实践为导向,帮助开发者掌握成为"调参大师&qu

深耕 Vue 生态与 JS/TS 技术,聚焦组件封装、响应式原理、TS 类型设计,解析工程化配置与性能优化方案。同时分享 YOLOv8 目标检测实战、AI 大模型面试核心考点,以代码实例拆解技术实现与业务解法。 1267

24、汽车黑客技术全解析:诊断代码、车库创建与系统攻防

本文深入探讨了汽车黑客技术的核心内容,包括诊断代码模式与参数ID、创建开放车库社区、汽车系统相关技术、硬件与软件工具、攻击与防御手段,以及车辆通信与网络安全。无论你是汽车安全研究人员、爱好者还是开发者,都能从中获取全面的技术解析与实践指南。

Apple的专栏 232

Hdu-1671 Phone List

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1671 题目大意: 给你很多电话号码,判断其中是否存在号码是其他号码的前缀,若存在,输出NO.否则输出YES 解题思路: 很简单的字典树的变形。只需要判断2种情况: 1. 9112然后输入911 2.911然后输入9112 通过这道题,认识了一种灰常巧妙的方法:空插法(自己起的名。...

peizhiinfo 151

IDEA的使用指南

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

HDU 1671 Phone List(字典树Trie)

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

code 1306

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

HDU 1671 Phone List

Phone List Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Given a list of phone numbers, determine if it is consistent in the

JYZ's Blog 373

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

hdu 1671 Phone List

这题的题解随处可见。仅供参考。 ac代码: View Code #include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include <string> #incl...

weixin_33758863的博客 223

HDU1671 Phone List

题目: 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:Emer

Monster_Day的博客 5073

HDU 1671 phone list

http://acm.hdu.edu.cn/showproblem.php?pid=1671 字典树的题目,在POJ上的时候字典树的话会因为不断开辟新的节点而消耗过多的时间,所以会开一个固定的空间..... 但是我不知道该开多大的空间....o(╯□╰)o 看别人的代码是开到 100000...话说我不知道为什么只要那么点就可以了.... Code 1 #include...

dicuanjiang7084的博客 133

HDU 1671 — Phone List

原题:http://acm.hdu.edu.cn/showproblem.php?pid=1671 题意: 给出一些号码,如果其中一个号码是另一个的前缀,则输出NO; 思路: 插入每个号码时,内部数字val = 0,最后一个数字val = 1; #include #include #define MAX 26 const int maxnode = 4000*100

吧唧吧唧 509

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 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: Emergency 911 Alice 97 625 999 Bob 91 12 54 26 In this ca

weixin_43808717的博客 178

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の博客 433

Phone List(HDU-1671)

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. Emergenc...

Alex_McAvoy的博客 463

hdu1671 Phone List

简单题~ 注意del(); #include #include #include #include #include #include #include #include #include #include using namespace std; struct trie { int is; trie* next[11]; }; char ch[11];

Johnbug 383
上一篇: noj 1121 Message Flood
下一篇: hdu 1251 统计难题
雨狮子
博客等级 码龄12年 24粉丝 185原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址