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数据库去除重复数据

    (一)最原始的方法: delete from test where id not in (select * from ((select min(id) from test group by(name) ...

  2. ubuntu openfire Server install

    1.首先登录到ubuntu server.在安装openfire 服务器之前,先确保你的系统已经更新到最新.然后输入下面的命令,一行一行执行,最后安装可用的更新 sudo apt-get update ...

  3. 在Servlet的GenericServlet类中为什么有两个init()方法

    想要搞清楚这件事情,必须先了解Servlet容器调用Servlet的过程.调用过程如下 首次访问该Servlet1.调用init(ServletConfig config) 进行初始化,Servlet ...

  4. mybatis介绍安装

    MyBatis 是支持定制化 SQL.存储过程以及高级映射的优秀持久层框架.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyBatis 可以对配置和原生Map使用简单 ...

  5. java并发阻塞队列

    Java 并发编程利用 Condition 来实现阻塞队列 You are here:  开发&语言 - Java 文章 发布于 2017年06月26日  阅读 944 并发编程   什么是阻 ...

  6. BlockingQueue的使用 http://www.cnblogs.com/liuling/p/2013-8-20-01.html

    BlockingQueue的使用 本例介绍一个特殊的队列:BlockingQueue,如果BlockQueue 是空的,从BlockingQueue取东西的操作将会被阻断进入等待状态,直到Blocki ...

  7. ftp put get 的使用方法

    首先:ftp user@ip 登录到远程主机 成功后,输入ls,如下: ftp> ls 可以得到远程主机的本地目录. 一:get命令(从远程主机下载文件到本机): ftp> get (re ...

  8. Python爬上不得姐 并将段子写入数据库

    #Python2.7 可以优化一下 前10页 每页点赞最多的段子 百思不得姐 # -*- coding: utf-8 -*-import MySQLdbimport urllib,urllib2imp ...

  9. hihoCoder #1388 : Periodic Signal

    NTT (long long 版) #include <algorithm> #include <cstring> #include <string.h> #inc ...

  10. 源码安装Apache,报错:Cannot use an external APR with the bundled APR-util

    一般在第一次源码安装是没有问题的,在版本变化情况下在次源码安装可能会遇到此问题: apache2.0.x与apache2.2.x在apr有很大区别,前者为依赖公用apr,后者依赖于自身的apr.一般前 ...