HihoCoder 1014 Trie树模板

2026年10月11日 ECOC 2026(第52届欧洲光通信大会)深度研究报告 本届大会吸引超过和,技术会议共发表,覆盖20个主题领域(——从全体会议、厂商发布到论文分布,"为AI集群提供光互连"取代传统电信传输成为绝对主线。本报告的核心结论有五点:其一,,行业讨论焦点已转向3.2T与400G/通道技术;其二,,行业共识转向"按场景分层部署"——scale-up、scale-out、scale-across各有最优解; 阅读详情

传送门:HihoCoder 1014

题解

熟练白书的数组模拟Trie树模板


AC code:

#include<iostream>
#include<cstring>
using namespace std;

const int maxn(1e6 + 5);

int cnt[maxn], ch[maxn][26];


int idx(char p){return p - 'a';}


struct Trie{

    int sz;

    Trie(){
        sz = 1;
        memset(cnt, 0, sizeof(cnt));
        memset(ch, 0, sizeof(ch));
    }

    void insert_node(char *s){
        int u = 0, len = strlen(s);

        for(int i = 0; i < len; ++i){
            int v = idx(s[i]);
            if(!ch[u][v]){
                ch[u][v] = sz++;
            }
            u = ch[u][v];
            ++cnt[u];
        }

    }

    int query(char *s){
        int u = 0, len = strlen(s);

        for(int i = 0; i < len; ++i){
            int v = idx(s[i]);
            if(!ch[u][v]) return 0;
            u = ch[u][v];
        }

        return cnt[u];
    }
};

int main(){

    int n, m;
    char s[15];

    while(cin >> n){

        Trie root;

        for(int i = 0; i < n; ++i) {
            cin >> s;
            root.insert_node(s);
        }

        cin >> m;
        while(m--){
            cin >> s;
            cout << root.query(s) << endl;
        }
    }


    return 0;
}
基于FFT+BP神经网络/决策树的轴承故障诊断 阅读详情

相关推荐

【气动弹性实战】基于Nastran与Patran的机翼颤振仿真:从模态分析到临界速度预测

本文详细介绍了基于Nastran与Patran的机翼颤振仿真全流程,从气动弹性问题解析、机翼建模技巧到模态分析与临界速度预测。通过实战案例展示如何利用SOL 145求解器进行颤振分析,并分享网格划分、材料属性设置等工程经验,帮助工程师有效解决飞行器设计中的气动弹性耦合问题。

weixin_33725722的博客 604

hihoCoder--1014 Trie树

题意给定一个词典,对于每一个给定的字符串,求以这个字符串开头的所有单词的个数。题解构建Trie树,节点附加一个域cnt,表示以从根到该节点结尾的字符串开头的单词个数。 每次insert一个单词,它经过的每个节点,其cnt都要加1。#include <iostream> #include <cstdio> #include <algorithm> #include <string> #include

许少y 439

介绍七种常见还危险的病毒(带样本)

简介:能够感染用户计算机bai系统中的.exe、.dll和.html文件,将自身加密以后缀加到目标文件中。样本(源文件):https://wwx.lanzoux.com/iJx4njrpz1c / https://wwx.lanzoui.com/iYRNLwd8ldc。英文名称:Virus.Win32.Viking.A(标准) / Worm.Win32.Fujack.A(标准)英文名称:Net-Worm.Win32.Blaster.A(标准)/ Lovesan.A/ Msblast.A。

2301_78858007的博客 8850

Hihicoder 题目1 : Trie树(字典树,经典题)

题目1 : Trie树 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助,在编程的学习道路上一同前进。 这一天,他们遇到了一本词典,于是小Hi就向小Ho提出了那个经典的问题:“小Ho,你能不能对于每一个我给出的字符串,都在这个词典里面找到...

weixin_33826268的博客 326

每日算法讲解(十):使用BP神经网络进行回归任务

BP神经网络是由输入层、隐藏层和输出层组成的多层前馈神经网络,通过反向传播算法(Backpropagation)来调整网络权重和偏置,以最小化预测误差。前向传播:将输入数据通过网络,计算每层的激活值和输出。计算误差:根据预测值和真实值之间的差异计算损失函数值。反向传播:从输出层开始,逐层向后计算梯度,并更新每层的权重和偏置。重复迭代:通过多次迭代,逐步减小预测误差,优化模型参数。接下来,我们定义一个包含一个输入层、两个隐藏层和一个输出层的BP神经网络模型。# 定义模型# 编译模型。

rhtee的博客 1736

T113-S3-官方SDK分区添加

本篇文章将展示如何编译T113-S3的SDK以及在sdk中添加用户自定义分区,让您能够轻松地开始在您的项目中使用T113-S3芯片。T113-S3是一款功能强大的嵌入式处理器,适用于各种应用,包括物联网、工业自动化和智能家居等。T113-S3-SDK是特别为T113-S3芯片设计的软件开发工具包(Software Development Kit)。它包含了一系列用于开发和定制嵌入式应用程序的工具、库和示例代码,方便开发者在T113-S3平台上开展软件开发工作。

flypig has a dream! 2367

hiho一下第二周 Hihocoder #1014 : Trie树

#1014 : Trie树 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助,在编程的学习道路上一同前进。 这一天,他们遇到了一本词典,于是小Hi就向小Ho提出了那个经典的问题:“小Ho,你能不能对于每一个我给出的字符串,都在这个

Luke的学习笔记 3646

【Zephyr存储专题】06_存储块设备驱动开发(Nand Flash)

本文介绍了基于Zephyr系统的NAND Flash驱动实现方案,重点阐述了Flash驱动模型的核心架构和关键API设计。

zero的博客 1810

hihoCoder 1014 Trie树(字典树入门)

题目链接:http://hihocoder.com/problemset/problem/1014(此题附入门讲解) 题面: #1014 : Trie树 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助,在编

David_Jett 2014

使用Google Earth Engine下载JRC全球水体数据

通过Google Earth Engine平台和提供的源代码,研究人员和水资源管理者可以方便地获取和利用这一重要的水资源监测数据集,从而开展相关的研究和决策支持工作。要使用Google Earth Engine下载JRC全球水体数据,首先需要在Google Earth Engine平台上进行注册和登录。JRC全球水体数据是由欧洲联合研究中心开发的高分辨率全球水体分类数据集,覆盖了整个地球的陆地和水域。下载完成后,你可以使用各种遥感数据处理软件来打开和分析这些数据,以满足不同的研究和应用需求。

LrlDebug的博客 1163

Xilinx FPGA平台DDR3设计保姆式教程(1)DDR3基础简介

xilinx平台DDR3设计(1)DDR3简介 如果我们只是拿来用ddr搬砖,那么它就简单,知道IP怎么使用就好,但是要想知其所以然,理论知识是必备的,这也是我们初学者所欠缺的东西,慢慢修炼吧! 目录 一、DDR3简介 二、地址的概念及容量计算 三、重要给概念理解 3.2 列地址脉冲选通潜伏期 3.4 掩码 四、参考资料 一、DDR3简介 DDR3全称double-data-rate 3 synchronous dynamic RAM,即第三代双倍速率同步动态随机存储器。...

数字IC/FPGA杂货铺,找一找,或许有你想要的~ 1万+

Hihocoder 1014Trie树(字典树模板)

时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助,在编程的学习道路上一同前进。 这一天,他们遇到了一本词典,于是小Hi就向小Ho提出了那个经典的问题:“小Ho,你能不能对于每一个我给出的字符串,都在这个词典里面找到以这个字符串开头的所有单词呢?

spark__s的博客 455

Ubuntu零基础入门到精通【1.2讲】:Ubuntu 与 Linux 的关系 —— 你用的到底是什么?

🏆 本文收录于 《滚雪球学 Ubuntu》 专栏。 本专栏面向有一定计算机基础,但尚未系统学习 Linux / Ubuntu 的读者,采用“滚雪球式学习法”:先装好、再会用、再理解、再优化、再实战,带你从第一次进入 Ubuntu 桌面 / 终端开始,逐步掌握 Ubuntu 的日常使用、命令操作、软件安装、系统配置、开发环境搭建与服务器部署能力。

**My Coding Family** 3517

hihocoder1014 trie树模板

描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助,在编程的学习道路上一同前进。 这一天,他们遇到了一本词典,于是小Hi就向小Ho提出了那个经典的问题:“小Ho,你能不能对于每一个我给出的字符串,都在这个词典里面找到以这个字符串开头的所有单词呢?” 身经百战的小Ho答道:“怎么会不能呢!你每给我一个字符串,我就依次遍历词典里的所有单

fan233的博客 528

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

WINCC7.3破解文件

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

hihoCoder 1014 Trie树 字典树模板

题目:http://hihocoder.com/problemset/problem/1014题意:首先给出一些字符串,代表字典里的单词。然后再给出一些字符串,询问字典中以当前字符串为前缀的单词个数思路:字典树模板题。留个模板 动态字典树,特点是好写好理解,确定是效率慢,有可能TLE//多实例记得调用trie_del函数清空字典树,单实例无所谓 #include <bits/stdc++.h> u

弱智就要多努力 504

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

hihocoder 1014 Trie树 (Trie 记模板 数组+指针)

hihocoder 1014 Trie树 (Trie 记模板 数组+指针)

Tc的专栏 1163

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

hihocoder 1014: Trie树(Trie树模板题)

题目链接 #include<bits/stdc++.h> using namespace std; const int L=12; struct T { int num; T* next[26]; T() { num=0; int i; for(int i=0;i<...

weixin_30375247的博客 77

Quartus Prime 18.0:数字电路教学与FPGA入门的稳定之选

FPGA开发工具的选择本质是工程适配性问题——在数字电路教学、Verilog/VHDL实验验证及小规模Cyclone系列FPGA开发中,稳定性、兼容性与学习友好性远比版本新旧更重要。Quartus Prime 18.0凭借成熟的综合布线引擎、精准的器件库支持(如Cyclone IV/V)、原生USB-Blaster驱动兼容性以及丰富的中文教学资源,构成了低门槛、高确定性的开发闭环。它规避了新版工具常见的时序收敛波动、驱动冲突与文档断层等工程风险,特别适合高校实验课、课程设计及嵌入式原型验证等场景。本文聚焦该

weixin_33861800的博客 316

Hihocoder #1014 : Trie树 (字典数树统计前缀的出现次数 *【模板】 基于指针结构体实现 )...

#1014 : Trie树 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助,在编程的学习道路上一同前进。 这一天,他们遇到了一本词典,于是小Hi就向小Ho提出了那个经典的问题:“小Ho,你能不能对于每一个我给出的字符串,都在这个词典里面找到以这...

weixin_30466421的博客 101

[hihoCoder 1014]Trie树[前缀树][前缀树的建立]

题目链接:[hihoCoder 1014]Trie树[前缀树][前缀树的建立] 题意分析:就是题目上那么写的题意XD 解题思路:建立前缀树 个人感受:当做模板记下,方便日后回忆。加了些个人注释~ 具体代码如下: #include #include #include #include using namespace std; const int MAXN = 1e6 + 111;

闲停 499

hihoCoder1014 Trie树

基本的tire树 加上模板 #include #include #include #include #include using namespace std; #define MAX 26 typedef struct tirenode { int nCount; // 该节点前缀 出现的次数 struct tirenode *next[MAX];//该节点的后续节点 }

但求心安的博客 409

hihoCoder1014 Trie树 [Trie]

Trie模板题 不同的是在建树时同时统计出现次数 模板请看 https://github.com/yyecust/icpctemplate/blob/master/%E5%AD%97%E7%AC%A6%E4%B8%B2.md#trie#include <bits/stdc++.h> using namespace std; int nextInt() { int x; scanf("%

more time 312

Trie树 Hihocoder 1014 Trie树

题目链接:http://hihocoder.com/problemset/problem/1014 题意:给一些字符串作为字典,再给一些前缀问前缀为这个的有多少个单词。 思路:Trie树模板。 建立的思想不难,用指针指向下一个字符。因为字符长度不定,而且如果是26字母的话就会过长,所以用指针来做最好。那么问题来了。 首先声明一个Trie的时候必须要把他里面标记置为0,把所有指向儿子的Tri

beihai2013 395

字典树模板(HihoCoder - 1014)

字典树模板(HihoCoder - 1014) #include <bits/stdc++.h> using namespace std; struct node{ int z[30];int sum=0; }tr[1000010]; //数组大小开n(插入最多单词个数)*l(最长单词长度) int num=0; void tr_insert(char s[]) { ...

weixin_43871404的博客 169

hihoCoder 1014 Trie树 (Trie)

#1014 : Trie树 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助,在编程的学习道路上一同前进。 这一天,他们遇到了一本词典,于是小Hi就向小Ho提出了那个经典的问题:“小Ho,你能不能对于每一个我给出的字符串,

sxk 871

[HihoCoder]#1014 : Trie树

华电北风吹 天津大学认知计算与应用重点实验室 2016-04-12题目链接:http://hihocoder.com/problemset/problem/1014题目分析:Trie树模板代码。// problem1014.cpp : 定义控制台应用程序的入口点。 // Trie树 // http://hihocoder.com/problemset/problem/1014 // 张正义

掉下个小石头 585
上一篇: UVA 11732 trie树 + 插入式比较
下一篇: HDU 1671 trie树
数论只会GCD
博客等级 码龄11年 229粉丝 320原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值