POJ Hardwood Species 2418(字典树)
来源:互联网 发布:淘宝直通车助手官网 编辑:程序博客网 时间:2024/05/17 22:06
Hardwood Species
Time Limit: 10000MS Memory Limit: 65536KTotal Submissions: 23536 Accepted: 9162
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.
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 AlderAshAspenBasswoodAshBeechYellow BirchAshCherryCottonwoodAshCypressRed ElmGumHackberryWhite OakHickoryPecanHard MapleWhite OakSoft MapleRed OakRed OakWhite OakPoplanSassafrasSycamoreBlack WalnutWillow
Sample Output
Ash 13.7931Aspen 3.4483Basswood 3.4483Beech 3.4483Black Walnut 3.4483Cherry 3.4483Cottonwood 3.4483Cypress 3.4483Gum 3.4483Hackberry 3.4483Hard Maple 3.4483Hickory 3.4483Pecan 3.4483Poplan 3.4483Red Alder 3.4483Red Elm 3.4483Red Oak 6.8966Sassafras 3.4483Soft Maple 3.4483Sycamore 3.4483White Oak 10.3448Willow 3.4483Yellow Birch 3.4483
Hint
This problem has huge input, use scanf instead of cin to avoid time limit exceeded.
Source
Waterloo Local 2002.01.26
题意:给出树的名字,统计每一颗树出现的频率,注意按字典序输出
没有别的,就是裸的字典树
#include <iostream>#include <string.h>#include <stdio.h>#include <stdlib.h>#include <algorithm>using namespace std;struct node{ int flag; int next[256];}q[51234];struct node1{ char str[40];}k[11234];int top;int cmp(node1 x,node1 y){ return strcmp(x.str,y.str)<0;}int newnode(){ q[top].flag=0; memset(q[top].next,-1,sizeof(q[top].next)); return top++;}void Insert(int p,char s[]){ int i,j,l,t; l=strlen(s); for(i=0;i<l;i++) { t=int(s[i]); if(q[p].next[t]==-1) { q[p].next[t]=newnode(); } p=q[p].next[t]; } q[p].flag++;}int query(int p,char s[]){ int l,i,j; l=strlen(s); for(i=0;i<l;i++) { int t=int(s[i]); if(q[p].next[t]==-1) { return 0; } p=q[p].next[t]; } if(q[p].flag!=0) { q[p].flag++; return q[p].flag; } else { return 0; }}int main(){ int n,m,i,j; m=0; char s[40]; top=0; n=newnode(); int g=0; while(gets(s)&&s[0]!='\0') { if(!query(n,s)) { strcpy(k[g++].str,s); //printf("%s\n",s); Insert(n,s); } m++; } //printf("%d\n",m); sort(k,k+g,cmp); for(i=0;i<g;i++) { int gg=query(n,k[i].str); printf("%s ",k[i].str); float xx,yy,zz; gg--; //printf("%d\n",gg); xx=float(gg); yy=float(m); printf("%.4f\n",xx/yy*100); } return 0;}
1 0
- POJ 2418 Hardwood Species (字典树)
- POJ 2418 Hardwood Species(字典树)
- [字典树] poj 2418 Hardwood Species
- 【字典树】POJ 2418 Hardwood Species
- POJ 2418 Hardwood Species(字典树)
- POJ 2418 Hardwood Species (字典树||MAP)
- POJ-2418-Hardwood Species-字典树
- POJ 2418 Hardwood Species(字典树)
- POJ---2418-Hardwood Species(字典树)
- poj 2418 Hardwood Species 字典树
- POJ 2418 Hardwood Species【字典树 / map】
- POJ Hardwood Species 2418(字典树)
- Hardwood Species 字典树 poj 2418
- poj 2418 Hardwood Species(字典树)
- (模板题)poj 2418 Hardwood Species(字典树)
- POJ 2418 Hardwood Species (字典树 || map)
- poj 2814(字典树Hardwood Species)
- Hardwood Species(字典树)
- POJ-2001 Shortest Prefixes(Trie树)
- 帧动画,补间动画,和属性动画
- 如何做一个简易的ATM机
- 敌兵布阵
- 图片水印的生成方法
- POJ Hardwood Species 2418(字典树)
- poj 1942 Paths on a Grid
- angular-translate for i18n and I10n
- python计算tfidf
- 图结构练习——判断给定图是否存在合法拓扑序列
- 贪心(弱)已知当前排名,倒推上月排名
- NSUserDefaults的使用
- Pineapple Incident
- android Activity(活动)详解