当前位置:网站首页>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;
}
边栏推荐
- Unity analog flashlight light source detector, AI attack range detection area, object detection in visual cone, fan-shaped area detection, circular area detection, cone area detection
- 一行代码可以做什么?
- Data processing and visualization of machine learning [iris data classification | feature attribute comparison]
- 合并两个有序数组
- unity动态读取外部音乐并播放
- The latest simulation test questions and answers of Henan construction electrician (special construction operation) in 2022
- PC e-commerce platform - search module
- The final scheme of adding traceid at the C end
- Leecode70 climbing stairs
- [专利与论文-19]:江苏省南京市2022年电子信息申报通知(中、高级)
猜你喜欢

js中的for.....in函数

提升四大性能!D-Wave发布下一代量子退火机原型

C语言数组与指针练习题(原题+解析+原码)

ASP.Net Core创建Razor页面上传多个文件(缓冲方式)

Caricature scientifique | Vous pouvez apprendre l'EEG en regardant les images. Voulez - vous essayer?

AXI_Bus_Matrix_4x4 设计 - 逻辑设计部分

【小程序】通过request实现小程序与后台asp.net的数据json传输(Post协议 图文+代码)

Cluster I -- LVS load balancing cluster NAT mode and LVS load balancing actual deployment

MySQL learning (from getting started to mastering 1.2)
![VLAN division based on interface: static VLAN [not perfect]](/img/ba/968b483c3ed96b283aa263dcb0ccdc.png)
VLAN division based on interface: static VLAN [not perfect]
随机推荐
Xcode plug-in management tool Alcatraz
2022年最新河南建筑施工电工(建筑特种作业)模拟试题及答案
向量與平面交點
ACM. HJ35 蛇形矩阵 ●
科研漫畫 | 看圖可以學腦電,來試試?
Citus 11 for Postgres is completely open source and can be queried from any node (citus official blog)
Principle and application of user mode hot patch
【yolov5】opencv450 加载onnx 进行推理 GPU 加速
About n before variables in SQL server and other usage analysis
The final scheme of adding traceid at the C end
拿什么来拯救你?我的注意力
自己动手写编译器:while,for,do等循环语句的中间代码生成
Delaying patient self-help guide | "I have 100 excuses for not delaying, but I am not willing to take a step"
Welcome to the markdown editor
Xshell7+xftp7 free download
RDKit | 分子所具有的自由基电子数、价电子数
Number of free radical electrons and valence electrons of rdkit | molecule
OpenJudge NOI 1.13 45:十进制到八进制
What is the C language callback function?
【微服务七】Ribbon负载均衡策略之BestAvailableRule源码深度剖析