POJ 之 Hardwood Species
Time Limit:10000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
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
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
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的更多相关文章
- [字典树] poj 2418 Hardwood Species
题目链接: id=2418">http://poj.org/problem?id=2418 Hardwood Species Time Limit: 10000MS Memory ...
- POJ 2418 Hardwood Species
Hardwood Species Time Limit: 10000MS Memory Limit ...
- [ACM] POJ 2418 Hardwood Species (Trie树或map)
Hardwood Species Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 17986 Accepted: 713 ...
- poj 2418 Hardwood Species (map)
题目:http://poj.org/problem?id=2418 在poj 上交题总是有各种错误,再次感叹各个编译器. c++ AC代码,G++为超时,上代码: #include<cstdio ...
- POJ 2418 Hardwood Species(STL在map应用)
职务地址:id=2418">POJ 2418 通过这个题查了大量资料..知道了非常多曾经不知道的东西. . .. 在代码中凝视说明吧. 代码例如以下: #include <ios ...
- POJ - 2418 Hardwood Species(map,trie,BST)
1.输入若干行树名,输入结束后,按字典序输出树名及其所占百分比. 2.多种方法:map,trie,BST 3. map: #include<iostream> #include<st ...
- 二叉搜索树 POJ 2418 Hardwood Species
题目传送门 题意:输入一大堆字符串,问字典序输出每个字符串占的百分比 分析:二叉搜索树插入,然后中序遍历就是字典序,这里root 被new出来后要指向NULL,RE好几次.这题暴力sort也是可以过的 ...
- POJ 2418 Hardwood Species( AVL-Tree )
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> ...
- POJ 2418 Hardwood Species (哈希,%f 和 %lf)
我的错因: 本来改用%f输出,我用了%lf,结果编译器直接判定为错误(一部分编译器认为lf是没有错的).当时我还以为是hash出错了.. 方法不止一种: 方法 时间 空间 Hash 891ms 5 ...
随机推荐
- 2.JAVA编程思想——一切都是对象
一切都是对象 欢迎转载.转载请标明出处:http://blog.csdn.net/notbaron/article/details/51040221 虽然以C++为基础,但 Java 是一种更纯粹的面 ...
- zabbix api创建screen vsize限制解决
通过脚本调用zabbix api 生成screen报错: "vsize": must be between "1" and "100" 查看 ...
- 使用spring-boot-admin对spring-boot服务进行监控(转自牛逼的人物)
尊重原创:http://www.cnblogs.com/ityouknow/p/8440455.html 上一篇文章<springboot(十九):使用Spring Boot Actuator监 ...
- OpenCV 3.1
http://www.tuicool.com/articles/FRfMni2 http://docs.opencv.org/3.1.0/d7/d9f/tutorial_linux_install.h ...
- Httpclient 实现带参文件上传
这里直接贴出的是我封装好的doPostFile方法,httpclient 的版本是3.1. public static String doPostFile(String url, Part[] par ...
- gulp配置,实例演示
项目完成后的目录 我们所需要的插件为:gulp-minify-css gulp-concat gulp-uglify gulp-rename del 如下图所示,完成后的项目目录结构: 附加,获取pa ...
- quartus2 13.0+modelsim联合开发环境搭建(win10)
quartus2用于硬件设计代码的综合,检查是否有语法错误:modelsim用于对硬件设计代码进行仿真,观察波形是否与需求一致,需要编写xxx_tb.v才能仿真 一.quartus2安装见这篇文章ht ...
- nexus5刷机
1.下载需要的刷机包,hammerhead-mra58k-factory-52364034.tgz 2.解压包到某个文件下,如D:\Download 3.重启手机进入fastboot模式下,也叫boo ...
- swift - 实现类似今日头条顶部标签和底部内容的动态解决方案
TYPageView TYPageView 类似今日头条 的标签导航解决方案,支持多种样式选择,基于swift3.0,支持文字颜色动态变化,底部选中线的动态变化 配图: 使用方法: let title ...
- python学习 02 元组
元组和列表除了能不能修改外 定义单一元组还需要加逗号