当前位置:网站首页>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;
}
边栏推荐
- IC科普文:ECO的那些事儿
- 无卷积骨干网络:金字塔Transformer,提升目标检测/分割等任务精度(附源代码)...
- [C language] three implementations of quick sorting and optimization details
- 【数字IC验证快速入门】7、验证岗位中必备的数字电路基础知识(含常见面试题)
- sun.misc.BASE64Encoder报错解决方法[通俗易懂]
- Minimum commission for stock trading account opening, where to open an account with low commission? Is it safe to open an account on your mobile phone
- leetcode刷题:二叉树15(找树左下角的值)
- Hong Kong stocks will welcome the "best ten yuan store". Can famous creative products break through through the IPO?
- When JS method passes long type ID value, precision loss will occur
- CTF reverse Foundation
猜你喜欢
走入并行的世界
A way to calculate LNX
Wechat applet regular expression extraction link
Elk distributed log analysis system deployment (Huawei cloud)
.Net分布式事務及落地解决方案
[quick start of Digital IC Verification] 6. Quick start of questasim (taking the design and verification of full adder as an example)
Based on vs2017 and cmake GUI configuration, zxing and opencv are used in win10 x64 environment, and simple detection of data matrix code is realized
Parler de threadlocal insecurerandom
【数字IC验证快速入门】9、Verilog RTL设计必会的有限状态机(FSM)
leetcode刷题:二叉树17(从中序与后序遍历序列构造二叉树)
随机推荐
C langue OJ obtenir PE, ACM démarrer OJ
银河证券在网上开户安全吗?
Rainbond 5.7.1 支持对接多家公有云和集群异常报警
Ffplay document [easy to understand]
Go language learning tutorial (XV)
Debezium series: PostgreSQL loads the correct last submission LSN from the offset
微信小程序正则表达式提取链接
Reinforcement learning - learning notes 4 | actor critical
[C language] three implementations of quick sorting and optimization details
Leetcode brush question: binary tree 14 (sum of left leaves)
计算lnx的一种方式
点云文件的.dat文件读取保存
Station B up builds the world's first pure red stone neural network, pornographic detection based on deep learning action recognition, Chen Tianqi's course progress of machine science compilation MLC,
2020 CCPC 威海 - A. Golden Spirit(思维),D. ABC Conjecture(大数分解 / 思维)
Leetcode skimming: binary tree 17 (construct binary tree from middle order and post order traversal sequence)
Mysql频繁操作出现锁表问题
Schema和Model
Oracle tablespace management
leetcode刷题:二叉树16(路径总和)
Scala基础【HelloWorld代码解析,变量和标识符】