POJ训练计划2418_Hardwood Species(Trie树)
解题报告
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;
}
Time Limit: 10000MS | Memory Limit: 65536K | |
Total Submissions: 18140 | Accepted: 7190 |
Description
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
Output
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
POJ训练计划2418_Hardwood Species(Trie树)的更多相关文章
- [ACM] POJ 2418 Hardwood Species (Trie树或map)
Hardwood Species Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 17986 Accepted: 713 ...
- poj 2513 Colored Sticks (trie 树)
链接:poj 2513 题意:给定一些木棒.木棒两端都涂上颜色,不同木棒相接的一边必须是 同样的颜色.求能否将木棒首尾相接.连成一条直线. 分析:能够用欧拉路的思想来解,将木棒的每一端都看成一个结点 ...
- poj 3630 Phone List trie树
Phone List Description Given a list of phone numbers, determine if it is consistent in the sense tha ...
- [POJ 1204]Word Puzzles(Trie树暴搜&AC自己主动机)
Description Word puzzles are usually simple and very entertaining for all ages. They are so entertai ...
- POJ 3630 Phone List | Trie 树
题目: 给定 n 个长度不超过 10 的数字串,问其中是否存在两个数字串 S, T ,使得 S 是 T 的前缀.多组数据,数据组数不超过 40. 题解: 前缀问题一般都用Trie树解决: 所以跑一个T ...
- poj 2513 Colored Sticks trie树+欧拉图+并查集
点击打开链接 Colored Sticks Time Limit: 5000MS Memory Limit: 128000K Total Submissions: 27955 Accepted ...
- POJ训练计划2777_Count Color(线段树/成段更新/区间染色)
解题报告 题意: 对线段染色.询问线段区间的颜色种数. 思路: 本来直接在线段树上染色,lz标记颜色.每次查询的话訪问线段树,求出颜色种数.结果超时了,最坏的情况下,染色能够染到叶子节点. 换成存下区 ...
- poj 2513 Colored Sticks (trie树+并查集+欧拉路)
Colored Sticks Time Limit: 5000MS Memory Limit: 128000K Total Submissions: 40043 Accepted: 10406 ...
- POJ 2418 Hardwood Species 【Trie树】
<题目链接> 题目大意: 给你一堆字符串,让你按字典序输出他们出现的频率. 解题分析: 首先,这是Trie数词频统计的题目,以Trie树的边储存字母,节点存储以该节点结尾的链所代表的字符串 ...
随机推荐
- 利用WinDbg找出程序崩溃的代码行号
之前碰到论坛里有几个好友,说程序不时的崩溃,什么xxoo不能read的! 如果光要是这个内存地址,估计你会疯掉~~ 所以分享一下基本的调试技巧,需要准备的工具有WinDbg + VC6.0, 下面是自 ...
- Bootstrapping (compilers) - Wikipedia, the free encyclopedia
Bootstrapping (compilers) - Wikipedia, the free encyclopedia Bootstrapping (compilers)
- Window平台搭建Redis分布式缓存集群 (一)server搭建及性能測试
百度定义:Redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对很多其它.包含string(字符串).list(链表).set(集合).zset(sort ...
- c#Lamdba表达式与托付
介绍: "Lambda表达式"(lambda expression)是一个匿名函数,在C#3.0中引入了lambda表达式,它是对匿名函数的一种简化,能够包括表达式和语句,而且可用 ...
- WSDL中文版——详解
为什么使用WSDL? 像Internet协议之类的标准有没有为权威所利用,或者人们这样看待它是因为顺之所获的好处远远超出了代价?曾经有许多试图建立的标准都流产了.有时候,那些还没有普遍使用的标准甚至由 ...
- ural 1519 Formula 1
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1519 题目分类:插头dp 题意:求经过所有可行点的哈密顿回路的个数 * 不可走 . 可 ...
- IP Editor IP控件(对比一下封装IP控件)
HWND hIpEdit; void __fastcall TForm2::FormCreate(TObject *Sender) { hIpEdit = CreateWindow(WC_IPADDR ...
- Ubuntu下Chromium源码的编译
一.失败的经历 印象中,谷歌建议Ubuntu建议版本为10.4.但是我找不到出处了,模糊的印象.不知道是不是这样? 1.Ubuntu10.4.3-desktop-amd64 + Virtual Box ...
- ZooKeeper的安装、配置、启动和使用(一)——单机模式
ZooKeeper的安装.配置.启动和使用(一)——单机模式 ZooKeeper的安装非常简单,它的工作模式分为单机模式.集群模式和伪集群模式,本博客旨在总结ZooKeeper单机模式下如何安装.配置 ...
- RIA Test:try catch 对 Error #1009 (无法访问空对象引用的属性或方法)的处理
功能: 实现登录账户的强制登录, 用If 判断当前账户是否可用.若可用,则跳出if体直接登录,若不可用,则进入If体点击 “强制登录” 按钮. 问题:如果不可用,则if 条件中的对象不可见,这样程序会 ...