Hardwood Species(水)
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
开始想用map水一下。。。 结果超时。。。
但是C++能过 ,G++就过不了
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<ctime>
#define eps 1e-6
#define LL long long
#define pii pair<string, int>
using namespace std;
char ch[50];
int main ()
{
map <string,int >mp;
map<string,int>::iterator it;
int coun=0;
while(gets(ch)&&strlen(ch))
{
string str(ch);
it = mp.find(str);
if( it != mp.end())
it->second = it->second+1;
else
mp.insert(pii(str,1));
coun++;
}
for( it=mp.begin() ; it != mp.end(); ++it){
cout << it->first;
printf(" %.4f\n",(it->second)*1.0/coun*100);
}
return 0;
}
#include <iostream>
#include <stdio.h>
#include <string.h>
#define MAX 128
using namespace std;
char A[50];
int coun = 0;
struct Trie
{
int endmark;
Trie*next[128];
Trie()
{
endmark=0;
for(int i=0;i<128;i++)
next[i]=NULL;
}
}root; void create(char *s)//将字符串s建立在trie树中
{
Trie *p=&root;
int len=strlen(s);
for(int i=0;i<len;i++)
{
int id=s[i];//唯一标识
if(p->next[id]==NULL)
p->next[id]=new Trie;
p=p->next[id];
}
p->endmark++;
}
void print(int deep , Trie * p) // dfs 按字典序输出字符串 , deep为递归的深度
{
if(p->endmark > 0 ){
for(int j=0;j<deep;j++)
printf("%c",A[j]);
printf(" %.4f\n",p->endmark*1.0/coun*100);
return ;
}
for(int i = 0 ; i < 128; i ++ )
{
if(p -> next[i] != NULL){
A[deep] = char(i) ;
//cout<<"---"<<(char)i<<" "<<p->next[i]->endmark<<"----\n";
print(deep+1 , p -> next[i]) ;
}
}
return ;
}
int main()
{
char s[35];
while(gets(s)&&strlen(s)!=0){
create(s);//根据给定的字符串建立字典树
coun++;
}
print(0,&root);
return 0;
}
Hardwood Species(水)的更多相关文章
- POJ 2418 Hardwood Species
Hardwood Species Time Limit: 10000MS Memory Limit ...
- POJ2418——Hardwood Species(map映射)
Hardwood Species DescriptionHardwoods are the botanical group of trees that have broad leaves, produ ...
- Hardwood Species 分类: POJ 树 2015-08-05 16:24 2人阅读 评论(0) 收藏
Hardwood Species Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 20619 Accepted: 8083 De ...
- 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 nu ...
- [ACM] POJ 2418 Hardwood Species (Trie树或map)
Hardwood Species Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 17986 Accepted: 713 ...
- POJ2418 Hardwood Species—二叉查找树应用
1. Hardwood Species原题描述 Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 14326 Acce ...
- POJ 之 Hardwood Species
Hardwood Species Time Limit:10000MS Memory ...
- [字典树] poj 2418 Hardwood Species
题目链接: id=2418">http://poj.org/problem?id=2418 Hardwood Species Time Limit: 10000MS Memory ...
- 洛谷 UVA10226 Hardwood Species
洛谷 UVA10226 Hardwood Species 洛谷评测传送门 题目描述 PDF 输入格式 输出格式 输入输出样例 输入 #1复制 输出 #1复制 题目翻译: 给定若干字符串,输出格式为:( ...
随机推荐
- 2 TKinter绑定事件
通过command属性给button绑定事件 目的:点击一下按扭,在窗口中出现一行字 第一种方法(command): #!/usr/bin/env python # _*_ coding:utf-8 ...
- Javax.mail.NoSuchProviderException: smtp
UT 这个错误是因为缺jar包 下载地址:在oralce下载一个 JavaMail 包 http://www.oracle.com/technetwork/java/javamail/index-13 ...
- Oracle常用知识小结
前言: 前一段时间项目开发数据库环境为Oracle,作为一个SQLer,表示各种不适应.所以刚开始的时候走了一些弯路,浪费了一席时间.因此就想把这些常用的东西给总结一下,算是对自己学习的总结,也希望能 ...
- (转)Android-Mac电脑如何进行APK反编译-使用apktool、jd-gui
最近群里有人问如何在mac下进行apk反编译,我也没试过,以前都是在windows下进行反编译的,windows下很简单,有许多比较好的集成工具,如apkide(改之理),不过我猜mac下应该和win ...
- jquery读取csv文件并用json格式输出
直接贴上代码: <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Untit ...
- 使用仓库管理器——Sonatype Nexus的九大理由
目前有很多组织使用了一些工具依赖于Maven仓库,但他们并没有采用一个仓库管理器,对于这一点我十分惊讶.可能没人提出来这一点,没人站出来告诉别人使用一个仓库管理器能带来什么好处.我经常能从很多不使用M ...
- Win8 安装驱动
从微软的网站上面下载了一些驱动,发现竟然没有Setup或者Install安装程序,囧. 快速查了一下,直接在inf文件右击的菜单里面选择“安装”即可.突然有点out的感觉. 参考:http://dig ...
- FindBugs插件
在日常开发过程中难免会因为一时疏忽而留下一些Bug,这些Bug就是埋在程序里的定时炸弹,如果不能及时铲除就会导致程序的不稳定,异常或闪退的现象,从而导致用户的体验的下降.那么怎么才能找出这些埋在程序里 ...
- socket 发送发送HTTP请求
socket方式: $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); //socket_set_option($socket, SOL_S ...
- HTML5表单与PHP交互
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...