hdu 1671 Phone List

稀疏阵列选型指南:互质阵、嵌套阵、MRA,谁才是你项目里的‘性价比之王’? 本文深入探讨了稀疏阵列技术中的互质阵、嵌套阵和MRA三大架构的工程化选型策略,重点分析了它们在DOA估计、自由度、旁瓣抑制和计算复杂度等核心指标上的表现。通过实际案例和配置示例,为智能天线、声学定位和毫米波雷达等应用场景提供技术选型指南,帮助研发团队在硬件成本与性能之间找到最佳平衡点。 阅读详情

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;
}


MATLAB基础应用精讲-【数模应用】PPO算法(附python代码实现)(二) 表示为状态转移概率和动作选择概率的乘积,因为状态和动作决定轨迹。 阅读详情

相关推荐

MATLAB与STK互联23:卫星对象操作(14)—仿真分析案例1,建立8个地面站,分析对卫星的可见性

学习到这里,我们有必要做个仿真分析案例,把之前我们学习的零散知识点串起来,看一下在真实的分析中怎么应用。 分析要求:建立8个地面站,分析每个地面站对某个轨道高度500km、倾角60°圆轨道的卫星,1天内的可见次数、可见弧长以及可见弧段间隔列表。 基本约束:地面站仰角8°~90°,作用距离<2000km,太阳矢量与地面站到卫星视线夹角不小于15°,可见弧段应大于30s。地面站站址可随机生成,但要求在南北纬50°范围内。 下面上代码: uiap = actxserver(‘STK11.application’)

ltylty001的博客 7490

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

吧唧吧唧 508

【锂离子电池力学耦合及相场法模拟技术与应用】

8. 电化学仿真软件的使用与案例分析 (1) 各向异性纳米线锂化应力分析(实例讲解1) (2) 化学反应及死锂现象研究(案例分析2)(3) 锂化循环损伤计算(案例分析3)6. 4. 电池材料的力学与电化学耦合性能分析(1) 耦合效应对电池性能的影响(2) 耦合模型的验证与应。5. 5. 电池颗粒、极片、电芯尺度力-电-化-热多场耦合模型概述力学-7. 颗粒尺度耦合模型在电池失效分析中的应用。2. 2. 电池电极材料的分类与特性。5. (2) 耦合模型的验证与应用。电化学耦合模型与仿真。

weixin_51101456的博客 520

hdu1671-Phone List

hdu1671-Phone List

lvy的专栏 644

Arduino蜂鸣器播放《Astronomia》:从乐谱到代码的嵌入式音乐实现

在嵌入式系统开发中,通过编程控制硬件执行特定任务是核心基础。其原理在于利用微控制器生成精确的时序和频率信号,驱动执行器(如蜂鸣器、电机)完成预定动作。这项技术的价值在于实现了软件逻辑与物理世界的直接交互,是物联网设备、智能硬件开发的基石。常见的应用场景包括电子玩具的音效生成、报警器设计以及交互式艺术装置。本文以热门歌曲《Astronomia》的播放为例,具体展示了如何运用Arduino的`tone()`函数和数组数据结构,将抽象的乐谱转化为可执行的频率与延时控制代码,完整呈现了从**核心硬件解析**到**软

weixin_29796279的博客 347

华为海思IC前端中后端(COT&XPU)岗位笔试机考题

华为海思COT和XPU部门IC前端,IC中端,IC后端岗位笔试真题分享

weixin_37584728的博客 3361

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

不慌不忙、不急不躁 1055

A-Level CS 计算机科学 考试知识点——考试介绍&第1章

前言:该系列文章是本人在给学生辅导本课程的过程中结合英文教材所总结的,该系列共分为30章,主要介绍了考试的核心知识点。若需要A-Level CS 计算机科学考试辅导也可以私信我。 目录 关于A-Level CS 计算机科学考试 考试简介 考试内容 考试时间 评分情况 第1章 信息表示 本章学习内容 1.01 数字系统 1.02 数字的内部编码 整数编码(Coding for integers) 二进制编码的十进制(Binary coded decimal——BCD) 1.03.

王俊的博客 6454

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

ndnSIM学习笔记(一)

在接下来的一段时间要用ndnSIM来做自己的仿真网络,需要系统的学习相关内容,以下为内容记录。1.安装      1.1核心依赖(必需的)             • python &gt;= 2.6             • libsqlite3             • libcrypto++             • pkg-config             • Boost lib...

gaonjzzz的博客 2985

MSTAR数据集下载地址及处理方法

首先感谢博主冯子材提供下载的百度网盘地址。 在这里为了防止侵权,特此鸣谢,并给出其博客地址。 地址中有MSTAR百度网盘下载地址和需要使用的数据介绍,其中百度网盘中有数据转换工具 https://blog.csdn.net/taifengzikai/article/details/80600355 工具使用 因为下载得到的数据是二进制文件,需要使用官方提供的工具进行转换,可将其转换为jpeg。 有...

KamenRider 1万+

HDU-1671-Phone List(字典树)

Problem DescriptionGiven 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 9

long-long-ago 716

高频电磁场仿真-主题064-伴随变量法与灵敏度分析

在电磁器件优化设计中,梯度信息对于指导优化方向至关重要。考虑一个典型的电磁优化问题: 其中 p=[p1,p2,...,pn]Tp = [p_1, p_2, ..., p_n]^Tp=[p1​,p2​,...,pn​]T 是设计参数向量(如几何尺寸、材料参数等)。传统有限差分法的困境:示例: 一个具有100个设计参数的天线优化问题伴随变量法(Adjoint Variable Method, AVM)通过引入伴随场,将梯度计算复杂度从 O(n)O(n)O(n) 降低到 O(1)O(1)O(1):伴随变量法在计算

kkchenjj的博客 410

HDU 1671 Phone List(字典树Trie)

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

code 1306

蓝牙模块HM-10手册

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

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

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 372

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

hdu 1671 Phone List

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

weixin_33758863的博客 223

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

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.否则输出YES 解题思路: 很简单的字典树的变形。只需要判断2种情况: 1. 9112然后输入911 2.911然后输入9112 通过这道题,认识了一种灰常巧妙的方法:空插法(自己

飘过的小牛 1486

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的博客 176

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

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的博客 462

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

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 382
上一篇: 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、付费专栏及课程。

余额充值