当前位置:网站首页>Informatics Olympiad 1337: [example 3-2] word search tree | Luogu p5755 [noi2000] word search tree
Informatics Olympiad 1337: [example 3-2] word search tree | Luogu p5755 [noi2000] word search tree
2022-07-05 20:17:00 【Jun Yi_ noip】
【 Topic link 】
ybt 1337:【 example 3-2】 Word search tree
Luogu P5755 [NOI2000] Word search tree
【 Topic test site 】
1. Dictionary tree
【 Their thinking 】
solution 1: Dictionary tree
Dictionary tree template questions . Learn about dictionary tree in csdn search “ Dictionary tree ” or “tire Trees ”.
This question says that the total length of the document does not exceed 32K, 32 K B = 32 ∗ 1024 B = 32768 B 32KB = 32*1024B = 32768B 32KB=32∗1024B=32768B, The total number of characters will not exceed 33000 individual . Therefore, the total number of node pools is set to 33000.
【 Solution code 】
solution 1: Dictionary tree
#include<bits/stdc++.h>
using namespace std;
struct Node
{
int child[26];//child[i]: Character is a i+'A' The address of the child node
};
Node node[33000];
int p, root;// Root node root The address is 0, From address 1 Start assigning nodes
void insert(string s)// Insert words into the dictionary tree s
{
int pf = root;// The address of the currently concerned node
for(int i = 0; i < s.length(); ++i)
{
if(node[pf].child[s[i]-'A'] == 0)
node[pf].child[s[i]-'A'] = ++p;// Assign new nodes
pf = node[pf].child[s[i]-'A'];//pf Point to the next node
}
}
int getNodeNum(int r)// Get the root node address as r Node number of the tree of
{
int sum = 1;// I am 1 Nodes
for(int i = 0; i < 26; ++i)// Statistics r Number of subtree nodes
{
if(node[r].child[i] > 0)
sum += getNodeNum(node[r].child[i]);
}
return sum;
}
int main()
{
string s;
while(cin >> s)
insert(s);// Put the word s Insert dictionary tree
cout << getNodeNum(root);// Get the node number of the whole tree
return 0;
}
边栏推荐
猜你喜欢
Mysql频繁操作出现锁表问题
实操演示:产研团队如何高效构建需求工作流?
B站UP搭建世界首个纯红石神经网络、基于深度学习动作识别的色情检测、陈天奇《机器学编译MLC》课程进展、AI前沿论文 | ShowMeAI资讯日报 #07.05
【数字IC验证快速入门】1、浅谈数字IC验证,了解专栏内容,明确学习目标
ROS2专题【01】:win10上安装ROS2
leetcode刷题:二叉树16(路径总和)
【数字IC验证快速入门】6、Questasim 快速上手使用(以全加器设计与验证为例)
About the priority of Bram IP reset
走入并行的世界
【数字IC验证快速入门】3、数字IC设计全流程介绍
随机推荐
基金网上开户安全吗?去哪里开,可以拿到低佣金?
nprogress插件 进度条
Oracle-表空间管理
A way to calculate LNX
2022年7月4日-2022年7月10日(ue4视频教程mysql)
Is it safe for CICC fortune to open an account online?
Go language | 01 wsl+vscode environment construction pit avoidance Guide
全国爱眼教育大会,2022第四届北京国际青少年眼健康产业展会
死信队列入门(两个消费者,一个生产者)
leetcode刷题:二叉树15(找树左下角的值)
Some problems encountered in cocos2d-x project summary
Mysql频繁操作出现锁表问题
[quick start of Digital IC Verification] 9. Finite state machine (FSM) necessary for Verilog RTL design
2022北京眼睛健康用品展,护眼产品展,中国眼博会11月举办
IC科普文:ECO的那些事儿
2020 CCPC 威海 - A. Golden Spirit(思维),D. ABC Conjecture(大数分解 / 思维)
618 "low key" curtain call, how can baiqiushangmei join hands with the brand to cross the "uncertain era"?
信息学奥赛一本通 1338:【例3-3】医院设置 | 洛谷 P1364 医院设置
计算lnx的一种方式
Autumn byte interviewer asked you any questions? In fact, you have stepped on thunder