poj_2418 Hardwood Species (字典序Trie树)

用 Python 和 XGBoost 进行疾病诊断预测 疾病诊断预测是医疗领域的重要研究方向,准确的疾病诊断预测可以帮助医生提前制定治疗方案,提高治疗效果,降低医疗成本。本文章的目的是介绍如何使用 Python 和 XGBoost 算法构建疾病诊断预测模型。范围涵盖了从数据预处理、模型训练到模型评估的整个流程,同时通过实际案例展示如何将该模型应用于疾病诊断预测中。本文首先介绍了疾病诊断预测的背景和 XGBoost 算法的核心概念,然后详细讲解了 XGBoost 算法的原理和具体操作步骤,包括 Python 代码实现。 阅读详情

又是一道典型的Trie树应用题,有了Trie树的基本知识,写起来就非常容易了~~

【题目描述】

Hardwoods are the botanical group of trees that have broad leaves, produce a fruit or nut, and generally go dormant in the winter. 
America's temperate climates produce forests with hundreds of hardwood species -- trees that share certain biological characteristics. Although oak, maple and cherry all are types of hardwood trees, for example, they are different species. Together, all the hardwood species represent 40 percent of the trees in the United States. 

On the other hand, softwoods, or conifers, from the Latin word meaning "cone-bearing," have needles. Widely available US softwoods include cedar, fir, hemlock, pine, redwood, spruce and cypress. In a home, the softwoods are used primarily as structural lumber such as 2x4s and 2x6s, with some limited decorative applications. 

Using satellite imaging technology, the Department of Natural Resources has compiled an inventory of every tree standing on a particular day. You are to compute the total fraction of the tree population represented by each species.

【题目要求】

Input to your program consists of a list of the species of every tree observed by the satellite; one tree per line. No species name exceeds 30 characters. There are no more than 10,000 species and no more than 1,000,000 trees.

Print the name of each species represented in the population, in alphabetical order, followed by the percentage of the population it represents, to 4 decimal places.

【样例输入】

Red Alder
Ash
Aspen
Basswood
Ash
Beech
Yellow Birch
Ash
Cherry
Cottonwood
Ash
Cypress
Red Elm
Gum
Hackberry
White Oak
Hickory
Pecan
Hard Maple
White Oak
Soft Maple
Red Oak
Red Oak
White Oak
Poplan
Sassafras
Sycamore
Black Walnut
Willow

【样例输出】

Ash 13.7931
Aspen 3.4483
Basswood 3.4483
Beech 3.4483
Black Walnut 3.4483
Cherry 3.4483
Cottonwood 3.4483
Cypress 3.4483
Gum 3.4483
Hackberry 3.4483
Hard Maple 3.4483
Hickory 3.4483
Pecan 3.4483
Poplan 3.4483
Red Alder 3.4483
Red Elm 3.4483
Red Oak 6.8966
Sassafras 3.4483
Soft Maple 3.4483
Sycamore 3.4483
White Oak 10.3448
Willow 3.4483
Yellow Birch 3.4483

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct node //儿子兄弟表示法
{
    char c;
    char s[50];
    long int num;
    struct node* fChild;
    struct node* rCousin;
}* triTree;

triTree newTree(char ch)
{
    triTree p=(triTree) malloc(sizeof(struct node));
    p->c=ch;
    p->num=0;
    p->fChild=NULL;
    p->rCousin=NULL;
    return p;
}

void setTree(triTree t, long int* total) //建立一棵字典序Trie树
{
    char s[50];
    while (gets(s)!=NULL) //需要用gets,因为树名中可能有空格
    {
        (*total)++; //注意*和++的优先级顺序
        int i,len=strlen(s);
        triTree x=t,y;
        for (i=0;i<len;i++)
        {
            y=x->fChild;
            if ((y==NULL)||((y!=NULL)&&(y->c > s[i]))) //当前结点没有长子或者长子字符大于待查字符时,剩余字符串按长子树插入
            {
                int k;
                triTree z=newTree(s[i]);

                x->fChild=z; x=z;
                for (k=i+1;k<len;k++){x->fChild=newTree(s[k]); x=x->fChild;}
                strcpy(x->s,s);
                x->num++;

                if (y!=NULL) z->rCousin=y;
                break;
            }

            while (y!=NULL)
            {
                if (y->c==s[i]) {x=y;break;}
                if (y->c<s[i]) x=y;
                y=y->rCousin;
            }
            if (y==NULL) //按非长子树插入,注意调整儿子关系
            {
                triTree z=newTree(s[i]);
                z->rCousin=x->rCousin;
                x->rCousin=z;
                x=z;

                int k;
                for (k=i+1;k<len;k++){x->fChild=newTree(s[k]);x=x->fChild;}
                strcpy(x->s,s);
                x->num++;
                break;
            }
        }
        if (i==len) x->num++; //重复字符串
    }
}

void print(triTree t, long int total) //先序遍历整个Trie树,字典序输出所有字符串统计
{
    if (t->num>0) printf("%s %.4f\n", t->s, 100.0*t->num/total);
    if (t->fChild!=NULL) print(t->fChild,total);
    if (t->rCousin!=NULL) print(t->rCousin,total);
}

int main()
{
    triTree t=newTree('0');
    long int total=0;
    setTree(t,&total);
    print(t,total);
    return 0;
}

三菱FX5U-PLC建立CClink的IO通讯 最新需要用三菱的FX5U的PLC搭建一个CClink通讯,PLC做主站,控制CClink从站的IO,下面2个输入模块AJ65SBTB1-32D,两个输出模块AJ65SBTB1-32T。3、在右侧的部件,选择网络模块:FX5-CCL-MS,CC-link主站模块。依次把加入两个AJ65SBTB1-32D,两个AJ65SBTB1-32T。7、基本设置,网络配置设置,链路刷新设置,设置好下面参数,应用。6、基本设置,网络配置设置,CC-Link配置设置。8、部件选择,模块,右键,添加模块标签。 阅读详情

相关推荐

用Java实现森林冰火人游戏

g.drawString("游戏结束", CELL_SIZE * COLS / 2 - 100, CELL_SIZE * ROWS / 2);g.drawString("难度级别: " + difficultyLevel, 10, CELL_SIZE * ROWS + 60);g.drawString("生命值: " + playerHealth, 10, CELL_SIZE * ROWS + 20);setTitle("森林冰火人");

2401_82778412的博客 1734

二叉树--字典树应用--Hardwood Species

传送门:Hardwood Species 总时间限制: 10000ms 内存限制: 65536kB 描述 Hardwoods are the botanical group of trees that have broad leaves, produce a fruit or nut, and generally go dormant in the winter. ...

天行健,君子以自强不息 1186

STM32平台下FreeModbus TCP协议栈集成指南

深入讲解在STM32平台如何移植和配置freemodbus协议栈,实现TCP通信功能。结合嵌入式开发细节,帮助开发者快速掌握freemodbus的应用与调试技巧。

weixin_36001279的博客 1144

fjnu 1601 Hardwood Species

DescriptionHardwoods are the botanical group of trees that have broad leaves, produce a fruit or nut, and generally go dormant in the winter. Americas temperate climates produce forests with hund

异リ度ュ空ウ間(镜像站) 866

使用pdfBox实现pdf转图片出现中文方块乱码 简单修改源码解决

参考文章 问题排查:使用pdfbox将pdf转image时STSong-Light字体中文乱码 pdfbox版本是2.0 日志中打印出类似这样的日志(例:Using fallback XXX for CID-keyed font STSong-Light),就说明系统没有安装STSong-Light字体,pdfbox使用XXX字体来替代了。如果出现方块,就说明没有这种字体,并且替代字体也没有,日志也有相应的其他提示。 正常操作就是安装缺失的 STSong-Light 字体,但是在网上搜到的都是 STSong

aji_csdn的博客 5266

EtherCAT-7 从站代码移植-SPI

STM32F103 + AX58100,从站代码移植。

tianya_xuan的博客 3571

POJ2418 Hardwood Species STL

水题 直接使用MAP即可 Hardwood Species Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 14927   Accepted: 6003 Description Hardwoods are the botanical group of trees

684

【灰度共生矩阵(GLCM)原理及代码实现】

文章主旨详细介绍灰度共生矩阵(Gray-Level Co-occurrence Matrix, GLCM)的生成原理、核心特征量及其在图像纹理分析中的应用,并提供了可运行的Python代码实现。该网页是一篇理论结合实践的优秀技术文章。它不仅清晰地解释了GLCM这一经典纹理分析工具背后的数学原理,还提供了完整、可复现的代码,非常适合计算机视觉或图像处理领域的学习者和开发者入门并实践灰度共生矩阵。读者可以通过运行代码来直观理解GLCM如何工作,并提取图像的纹理特征。

blotemj.blog.youkuaiyun.com 180

poj 2418 Hardwood Species 字典树

Hardwood Species Description Hardwoods are the botanical group of trees that have broad leaves, produce a fruit or nut, and generally go dormant in the winter. America's temperate clima

colorfulshark 946

CAPL学习之路-关键字

在capl中,关键字具有特殊的含义和用途,因此,不得将关键字用作变量或函数的名称 声明数据类型的关键字 可以用不同的关键字,声明或引用不同类型的数据 byte 声明一个字节的变量 word 声明两个字节的变量 dword 声明四个字节的变量 int 声明两个字节的整数 long 声明四个字节的变量 qword 声明八个字节的变量 char 声明一个字符串 float 声明一个浮点数,8个字节 double 声明一个浮点数,8个字节 定义一个结构体或枚举类型 struct struct Data { .

jasonj333 6108

架构师成长之路(1)--什么是架构师

前言: 哲学家常思考的问题:" 我是谁?"" 我从哪里来?"" 要到哪里去?不只是哲学家,我想每个人都有自己对这三个问题的认知。 如果我们要成为架构师,我们自己要面临的三大问题: 找准自己定位:我是谁?在哪里? 怎样做好架构师:我要做什么? 如何搭建架构师知识体系:我该怎么做? 这里面就是做事方法论:目标(我要做什么),方法(计划)(我该怎么做), 执行/行动找准自己定位:我是谁?在哪里...

黄规速博客:学如逆水行舟,不进则退 6万+

Hardwood Species(字典树)

Hardwood Species Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 24133   Accepted: 9364 Description Hardwoods are the botanical group of trees that have broad

jinzk123的博客 508

VS Code下载安装与使用教程

VSCode下载安装与使用教程

weixin_46713695的博客 4万+

POJ 2418 ,ZOJ 1899 Hardwood Species - from lanshui_Yang

Description Hardwoods are the botanical group of trees that have broad leaves, produce a fruit or nut, and generally go dormant in the winter.  America's temperate climates produce forests with hund

lanshui_Yang的专栏 1万+

VB摄像头监控

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

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

POJ 2418 Hardwood Species (trie树\map)

Description Hardwoods are the botanical group of trees that have broad leaves, produce a fruit or nut, and generally go dormant in the winter. America's temperate climates produce forest...

bandiaodai5734的博客 177

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

poj 2418 Hardwood Species (trie 树)

题意:给定一些树的种类名,求每种树所占的百分比,并按字典序输出 分析:实质就是统计每种树的数量n,和所有树的数量m, 百分比就为 n*100./m 由于数据达到一百万,直接用数组查找肯定超时, 可以用trie树,空间换取时间

happy_lcj 907

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

POJ2418 Hardwood Species Tire树

题目大意:若干棵树构成一片树林,我们知道每一棵树的名字,按树名字典序输出每种一树所占的比率。 分析:由于树名不止是一个单词,可以用gets输入,输入的同时记录树的数量,字符串排序后遍历一遍即可。为了保证重复树名只输出一次,我们可以在每种树输出一次后标记它的状态,下次不再重复输出。 实现代码如下: #include #include #include #inclu

AC_Gibson的专栏 460

POJ 2418 Hardwood Species(字典树||map)

字典树 传送门 题目大意 给你很多个单词,要你统计单词出现的次数,最后按字典升序输出 思路 因为字典序的先序遍历是排序的,所以只需建好树后先序遍历一下树就可以满足题目要求的输出方式了。裸的Trie树,输出按字符串的字典序输出,所以插入的时候,把第一次出现的字符串暂时保存起来。以后排完序在查询输出即可 字典树代码 struct node{ int val; int child[130]; node(){ val=0; memset(child,0,sizeof child); } }tire[

幼儿园大哥~ 237

POJ 2418 Hardwood Species

这个题可以用多种方法解决。 题目大意: 就是输入一堆字符串,可能重复,按字典序输出,并输出占的比例。 可以用字典树,二叉查找树,Map,快排等等多种方法。 我用的二叉查找树,下面是代码: #include #include #include struct node { int cut; char c[40]; struct node *l,*r; } h

脑残的孩子只有慢慢学。。 4017

poj 2418 Hardwood Species

Hardwood Species Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 19313   Accepted: 7609 Description Hardwoods are the botanical group of trees that have b

Jinbao 770

POJ 2418 Hardwood Species (字典树+dfs)

题意: 给若干个串,求每一个串出现的频率。 按字典序输出:串 频率*100 例如:Ash 13.7931 ps: 频率为该串出现的次数除以总串数 Sample Input Red Alder Ash Aspen Basswood Ash Beech Yellow Birch Ash Cherry Cottonwood Ash Cypress Red Elm Gum Hackberry White ...

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz 513

poj-2418 Hardwood Species

题目数据很长就不放描述了。    题意:美国有各种各样不同的树木,你需要输入树木的名字,并且最后统计出每种树木所占的比例,并按字典序输出。 思路:字典树存储树的名字,统计每种树木的数量。除以输入数据的数量得到比例,最后输出即可,本题没有什么很难的算法,读懂题意就可以AC。 #include #include #include #include #include using

心の コード 890

[ACM] POJ 2418 Hardwood Species (Trie树或者map)

Hardwood Species Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 17986   Accepted: 7138 Description Hardwoods are the botanical group of trees that have b

逆风的方向 更适合飞翔 2996

poj 2418 Hardwood Species

题目链接:点击打开链接 Description Hardwoods(硬木) are the botanical(植物学的) group of trees that have broad leaves, produce a fruit or nut, and generally go dormant(休眠的) in the winter.  America's temperate(

Vision 525

poj-2418 Hardwood Species(用map处理字符串)

题目链接 poj2418 题意 题意:美国有各种各样不同的树木,你需要输入树木的名字,并且最后统计出每种树木所占的比例,并按字典序输出。 代码 #include<iostream> #include<map> #include<string> #include<iomanip> #include<cstdio> using namespace std; int main() { //freopen("data.txt","r",stdin);

weixin_47750287的博客 177

poj 2418Hardwood Species

题意是将输入的字符串按字典序输出,并且输出它出现的次数的百分比。 典型的字典树问题,建树并记录出现的次数就OK了啊、注意输入以Ctrl+Z退出、、 Hardwood Species Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 15937   Accepted: 6381

I am a slow walker, but I never walk backwards! 2276
上一篇: 练习:Trie树(公共前缀)
下一篇: poj_2945 Find the Clones (Trie树 内存分配)
薄帷清风
博客等级 码龄11年 31粉丝 44原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值