Hardwood Species

Time Limit:10000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

 

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.

代码分析:(以后再写)

#include <stdio.h>
#include <string.h>
#include <string>
#include <cstring>
#include <map>
#include <algorithm> using namespace std; int main()
{
char s[35];
double cnt;
map<string, double>ma;
map<string, double>::iterator it = ma.begin(); cnt=0;
while(gets(s)!=NULL)
{
ma[s]++;
cnt++;
}
//int n=ma.size(); //sort(ma.begin(), ma.end() ); double dd;
for(it=ma.begin(); it!=ma.end(); it++ )
{
dd = it->second*100.0/cnt;
it->second = dd;
printf("%s %.4lf\n", it->first.c_str(), dd );
} return 0;
}

POJ 之 Hardwood Species的更多相关文章

  1. [字典树] poj 2418 Hardwood Species

    题目链接: id=2418">http://poj.org/problem?id=2418 Hardwood Species Time Limit: 10000MS   Memory ...

  2. POJ 2418 Hardwood Species

                                                     Hardwood Species Time Limit: 10000MS   Memory Limit ...

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

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

  4. poj 2418 Hardwood Species (map)

    题目:http://poj.org/problem?id=2418 在poj 上交题总是有各种错误,再次感叹各个编译器. c++ AC代码,G++为超时,上代码: #include<cstdio ...

  5. POJ 2418 Hardwood Species(STL在map应用)

    职务地址:id=2418">POJ 2418 通过这个题查了大量资料..知道了非常多曾经不知道的东西. . .. 在代码中凝视说明吧. 代码例如以下: #include <ios ...

  6. POJ - 2418 Hardwood Species(map,trie,BST)

    1.输入若干行树名,输入结束后,按字典序输出树名及其所占百分比. 2.多种方法:map,trie,BST 3. map: #include<iostream> #include<st ...

  7. 二叉搜索树 POJ 2418 Hardwood Species

    题目传送门 题意:输入一大堆字符串,问字典序输出每个字符串占的百分比 分析:二叉搜索树插入,然后中序遍历就是字典序,这里root 被new出来后要指向NULL,RE好几次.这题暴力sort也是可以过的 ...

  8. POJ 2418 Hardwood Species( AVL-Tree )

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

  9. POJ 2418 Hardwood Species (哈希,%f 和 %lf)

    我的错因: 本来改用%f输出,我用了%lf,结果编译器直接判定为错误(一部分编译器认为lf是没有错的).当时我还以为是hash出错了.. 方法不止一种: 方法 时间   空间 Hash 891ms 5 ...

随机推荐

  1. mysql innodb_data_file_path配置增加

    在配置innodb_data_file_path=ibdata1:200M:autoextend时,想增加空间,默认文件不断增加直到200M,如果要增加大小,直接修改参数增加大小会报错: auto-e ...

  2. java游戏开发之基础

    © 版权声明:本文为博主原创文章,转载请注明出处 游戏图形界面开发基础 AWT:(Abstract Window Toolkit,抽象窗口工具集) AWT中包含图形界面编程的基本类库,是Java语言G ...

  3. 高盛CEO致大学毕业生:要与有野心的人为伍

    我认为讲的非常棒.年轻人就要这样. 高盛集团首席运行官(CEO)劳尔德-贝兰克梵(Lloyd Blankfein)周四在曼哈顿贾维茨中心參加了拉瓜迪亚社区大学的第41届毕业典礼并发表演讲.在面向约10 ...

  4. 点击单选button后的文字就可以选定相应单选button

    比方我想点击单选button后的文字就选中对应的button: <input type="radio" name="sex" value="1& ...

  5. openWRT自学计划安排

    目标:充分理解openwrt的框架构成,能够在openwrt框架下实现:开发新程序,修改现有程序,修改内核,修改boot.为此,制定如下计划: 一.如何在openwrt上做开发 1.编译出一个BRCM ...

  6. linux .vimrc的设置!

    0.记得在配之前先下载vim.不同的版本下载vim使用不同命令 ubuntu使用sudo apt-get install vim 1.vi ~/.vimrc  打开当前用户下的vim的配置文件(修改完 ...

  7. IE 下 log 调试的一点不同

    介绍一点IE下控制台调试与chrome的区别 数组 alert([1,2]) console.log([1,2]) console.log([1,2],"1,2") alert I ...

  8. Cannot merge new index 65781 into a non-jumbo instruction! 问题解决(网上摘抄)

    我的报了这个错 Error:Execution failed for task ':app:transformClassesWithDexForDebug'.> com.android.buil ...

  9. 编程算法 - 二叉树的最低公共祖先 代码(C)

    二叉树的最低公共祖先 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 二叉树的最低公共祖先(lowest common ancestor), 首先先序遍 ...

  10. diamond源码阅读-目录监控

    PathNode(Path)StandardWatchEventKind(WatchEvent)Watchable(WatchKey WatchService WatchEvent)WatchKey( ...