当前位置:网站首页>F - phone list HDU - 1671 (dictionary tree prefix)
F - phone list HDU - 1671 (dictionary tree prefix)
2022-06-21 21:28:00 【fighting_ yifeng】
The question : Give you a list of phone numbers to see if there is a prefix for other numbers .
analysis : To judge the prefix, we only need to see whether the previous string is the prefix of the existing string or the prefix of the following string .
(1) The prefix of the string has appeared . use flag Represents whether a word ending in this node appears ;
(2) use sum Represents the number of words prefixed by the end of the node , Add judgment conditions in the middle .
#include<iostream>
#include<cstdio>
#include<map>
#include<string.h>
#include<cstring>
using namespace std;
const int maxn = 100010;
string a, b;
int trie[maxn][12], tot;
int m, rt, t, flag[maxn], ans, sum[maxn];
void insertit(int rt, string str)
{
int len = str.size();
for(int i = 0; i < len; i++)
{
int x = str[i] - '0';
if(trie[rt][x] == 0) trie[rt][x] = ++tot;
rt = trie[rt][x];
if(flag[rt]) ans = 1;
sum[rt]++;
}
if(sum[rt] > 1) ans = 1;
flag[rt]++;
}
int main()
{
scanf("%d", &t);
while(t--)
{
rt = 1; tot = 1;
scanf("%d", &m);
ans = 0;
while(m--)
{
cin >> a;
insertit(rt, a);
}
if(ans) puts("NO");
else puts("YES");
memset(flag, 0 ,sizeof(flag));
memset(trie, 0, sizeof(trie));
memset(sum, 0, sizeof(sum));
}
return 0;
}
边栏推荐
- Number of free radical electrons and valence electrons of rdkit | molecule
- DEDECMS织梦后台邮箱验证发送邮件配置教程
- Que peut faire une ligne de code?
- On the charm of code language
- 提升四大性能!D-Wave发布下一代量子退火机原型
- 2022 National latest fire facility operator (intermediate fire facility operator) simulation question bank and answers
- Xshell7+Xftp7免费版下载
- Mysql database transaction
- Go语言自学系列 | golang标准库encoding/xml
- MediaCodec的数据类型和使用方式
猜你喜欢
![[Internet of things development] punctual atom STM32 warship v3+ smart cloud aiot+app control](/img/78/90f7eca3ca9504a7f8b232e577ae03.png)
[Internet of things development] punctual atom STM32 warship v3+ smart cloud aiot+app control
![[专利与论文-20]:江苏省南京市2022年电子信息申报操作指南](/img/bb/313f4a9f9c03ab2e9dfe0e8846831e.png)
[专利与论文-20]:江苏省南京市2022年电子信息申报操作指南

Welcome to the markdown editor

This real-time monitoring scheme is really excellent!

JS中的构造函数(重点)

【MySQL·水滴计划】第三话- SQL的基本概念

2022 National latest fire facility operator (intermediate fire facility operator) simulation question bank and answers

数据库管理:Navicat Premium 15

What plug-ins are available for vscade?
![[server data recovery] a case of RAID5 data recovery of an EMC server](/img/cc/23adaa1f8bc57d350e4a5647ff9296.jpg)
[server data recovery] a case of RAID5 data recovery of an EMC server
随机推荐
Mysql database transaction
C语言回调函数到底是怎么回事?
N - String Problem HDU - 3374(最大最小表示法模板)
evaluating expression ‘ew.sqlSegment != null and ew.sqlSegment != ‘‘ and ew. mybaties plus问题
Principle and application of user mode hot patch
安全加密简介
2016 ICLR | Adversarial Autoencoders
Welcome to the markdown editor
MediaCodec的数据类型和使用方式
Cluster I - LVS Load Balancing Cluster Nat Mode and LVS Load Balancing Field Deployment
Merge two ordered arrays
K - Clairewd’s message HDU - 4300 (EXKMP)
RDKit | 分子所具有的自由基电子数、价电子数
如何解决织梦文章列表自动更新点击次数
智力题整理总结
matplotlib plt. Details of subplots()
Mysql database - Database Foundation
matplotlib plt.subplots()详解
Quels sont les conseils que les programmeurs débutants ne connaissent pas?
有哪些新手程序員不知道的小技巧?