解题报告

Tire树。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
struct node
{
int v;
node *next[256];
};
int cnt=0,q;
char ch[100],str1[100];
node *newnode()
{
node *p=new node;
p->v=0;
for(int i=0; i<256; i++)
p->next[i]=NULL;
return p;
}
void add(node *root,char *str)
{
node *p=root;
int n=strlen(str);
for(int i=0; i<n; i++)
{
int t=str[i];
if(p->next[t]==NULL)
{
p->next[t]=newnode();
}
p=p->next[t];
}
p->v++;
}
int fine(node *root,char *str)
{
node *p=root;
int n=strlen(str);
for(int i=0; i<n; i++)
{
int t=str[i];
if(p->next[t]==NULL)
return 0;
p=p->next[t];
}
return p->v;
}
void dfs(node *p)
{
if(p->v)
{
ch[q]=0;
printf("%s %.4lf\n",ch,(100.0*p->v)/cnt);
}
for(int i=0; i<256; i++)
{
if(p->next[i])
{
ch[q++]=i;
dfs(p->next[i]);
q--;
}
}
}
int main()
{
node *root=newnode();
//freopen("1","r",stdin);
q=0;cnt=0;
while(fgets(str1,100,stdin)!=NULL)
{
cnt++;
int l=strlen(str1);
str1[l-1]=0;
add(root,str1);
}
dfs(root);
return 0;
}

Hardwood Species
Time Limit: 10000MS   Memory Limit: 65536K
Total Submissions: 18140   Accepted: 7190

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 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

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.

Output

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.

Sample Input

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

Sample Output

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

Hint

This problem has huge input, use scanf instead of cin to avoid time limit exceeded.

POJ训练计划2418_Hardwood Species(Trie树)的更多相关文章

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

    Hardwood Species Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 17986   Accepted: 713 ...

  2. poj 2513 Colored Sticks (trie 树)

    链接:poj 2513 题意:给定一些木棒.木棒两端都涂上颜色,不同木棒相接的一边必须是 同样的颜色.求能否将木棒首尾相接.连成一条直线. 分析:能够用欧拉路的思想来解,将木棒的每一端都看成一个结点 ...

  3. poj 3630 Phone List trie树

    Phone List Description Given a list of phone numbers, determine if it is consistent in the sense tha ...

  4. [POJ 1204]Word Puzzles(Trie树暴搜&amp;AC自己主动机)

    Description Word puzzles are usually simple and very entertaining for all ages. They are so entertai ...

  5. POJ 3630 Phone List | Trie 树

    题目: 给定 n 个长度不超过 10 的数字串,问其中是否存在两个数字串 S, T ,使得 S 是 T 的前缀.多组数据,数据组数不超过 40. 题解: 前缀问题一般都用Trie树解决: 所以跑一个T ...

  6. poj 2513 Colored Sticks trie树+欧拉图+并查集

    点击打开链接 Colored Sticks Time Limit: 5000MS   Memory Limit: 128000K Total Submissions: 27955   Accepted ...

  7. POJ训练计划2777_Count Color(线段树/成段更新/区间染色)

    解题报告 题意: 对线段染色.询问线段区间的颜色种数. 思路: 本来直接在线段树上染色,lz标记颜色.每次查询的话訪问线段树,求出颜色种数.结果超时了,最坏的情况下,染色能够染到叶子节点. 换成存下区 ...

  8. poj 2513 Colored Sticks (trie树+并查集+欧拉路)

    Colored Sticks Time Limit: 5000MS   Memory Limit: 128000K Total Submissions: 40043   Accepted: 10406 ...

  9. POJ 2418 Hardwood Species 【Trie树】

    <题目链接> 题目大意: 给你一堆字符串,让你按字典序输出他们出现的频率. 解题分析: 首先,这是Trie数词频统计的题目,以Trie树的边储存字母,节点存储以该节点结尾的链所代表的字符串 ...

随机推荐

  1. 【从cocos2d-x学习设计模式】第一阶段:辛格尔顿

    设计模式,它总结了前辈在许多方案重用代码.它是一个想法. 因为我们爱cocos2d-x,然后我们从去cocos2d-x在设计模式中,右一起学习!本篇解释未来辛格尔顿. 提cocos2d-x中间Dire ...

  2. hadoop源码下载地址

    http://svn.apache.org/repos/asf/hadoop/common/branches/

  3. rsyslog+LogAnalyzer 日志收集

    Linux 之rsyslog+LogAnalyzer 日志收集系统 一.LogAnalyzer介绍 LogAnalyzer工具提供了一个易于使用,功能强大的前端,用于搜索,查看和分析网络活动数据,包括 ...

  4. 硬盘重装Ubuntu12.04的感受

    好久没更blog了,最近这两天系统也出了问题,win7蓝屏,ubuntu进不去-.后来win7整好了,ubuntu依旧顽固.用惯了linux,就不想在转到win7下面了,估计是习惯了各种敲命令的感觉吧 ...

  5. Lambda高手之路第三部分

    转http://www.cnblogs.com/lazycoding/archive/2013/01/06/2847587.html 背后的秘密-MSIL 通过著名的LINQPad,我们可以更深入的查 ...

  6. UIButton return(textField textView)

    首先设置TextField 或 TextView的 delegate /////UITextView - (BOOL)textView:(UITextView *)textView shouldCha ...

  7. BT5 firefox Flash插件问题

    今天在BT下安装了Nessus,好不容易安装好了,注册成功,本以为大功告成,但是在最后关头,却出现一个“未安装flash插件”错误,在bT下尝试着安装flahs插件,蛋碎一地,,,没能解决. 我的BT ...

  8. android怎样查看当前project哪些profile是打开的

    代码project里面有三仅仅文件都是涉及到各个profile的宏的,各自是:featureoption.java.common/ProjectConfig.mk.product/ProjectCon ...

  9. HDU4719-Oh My Holy FFF(DP线段树优化)

    Oh My Holy FFF Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) T ...

  10. window应用移植到Linux下(应用移植)

     配置QT的环境变量,这台电脑à属性à高级系统设置à高级à环境变量à系统变量àpathàC:\Qt\Qt5.3.0\5.3\mingw482_32\bin;C:\Qt\Qt5.3.0\Tools\ ...