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. Unmapped Spring configuration files found.

    © 版权声明:本文为博主原创文章,转载请注明出处 1.问题描述: 搭建SSH框架后,IDEA弹出如下提示: 2.解决方案: File --> Project Structure --> M ...

  2. Google 商店

    Google 商店地址:https://store.google.com/

  3. CAN协议学习(一)协议介绍

    一.简介 CAN 是 Controller Area Network 的缩写(以下称为 CAN),是 ISO 国际标准化的串行通信协议. 在当前的汽车产业中,出于对安全性.舒适性.方便性.低公害.低成 ...

  4. Swift开发图解入门

    <论语·卫灵公>有一段经典对白:『子贡问为仁.子曰:工欲善其事,必先利其器. --』. 对于一个程序猿来说,好的工具不意味着一定能产生优质的代码.可是好的工具对提升开发效率的作用还是不言而 ...

  5. SetTimer时间间隔的问题

    1.用WM_TIMER来设置定时器   SetTimer函数的原型 UINT_PTR SetTimer( HWND hWnd,                      // 窗体句柄 UINT_PT ...

  6. object.Equals与object.ReferenceEquals方法

    object.Equals方法表达的是语义判等,不一定是引用判等. object.ReferenceEquals方法是肯定是引用判等. 怎么实现一个对象的值语义的 Equals方法?实验. MyCla ...

  7. mysql5.5.30源码安装及主从搭建

    双机热备(实验环境) 主服务器:ip地址192.168.100.244,mysql版本5.5.30,源码安装 从服务器:ip地址192.168.100.245 一.源码安装mysql5.5 启动目录: ...

  8. 从xhr说起

    原生xhr对象存在较多的兼容性,IE6及之前版本使用ActiveXObject对象来创建,IE7以后使用兼容版本的MSXML2.XMLHttp.MSXML2.XMLHttp3.0.MSXML2.XML ...

  9. 反射机制,jvm,class类型

    [说明]这是上午完成的内容或者说是接触到的知识点,包括servlet简单的数据库连接,表格的显示需要用到的插件jstl,还有最最多的java反射原理的讲解 1)数据库的设计 2)编程中用到的知识点 3 ...

  10. [精]poj2724

    Purifying Machine Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5027   Accepted: 1455 ...