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 ...
随机推荐
- SpannableString 设置一段文字中部分字体颜色
SpannableString strTitle = new SpannableString("病情描述(必填项,请至少填写20个字)"); strTitle.setSpan(ne ...
- git删除所有历史提交记录,只留下最新的干净代码
git删除所有历史提交记录,只留下最新的干净代码 1.Checkout git checkout --orphan latest_branch 2. Add all the files git add ...
- 篇章一:[AngularJS] 使用AngularAMD動態載入Controller
前言 使用AngularJS來開發Single Page Application(SPA)的時候,可以選用AngularUI Router來提供頁面內容切換的功能.但是在UI Router的使用情景裡 ...
- vue实践---vue配合express实现请求数据mock
mock数据是前端比较常见的技术,这里介绍下vue配合express 实现请求数据mock. 第一步: 安装 express : npm install express -D 第二步: 简历需要mo ...
- android webview 加载本地html 实现 与 java 之间的相互响应
1.布局 <?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:androi ...
- python 基础 9.10 删除数据
#/usr/bin/python #-*- coding:utf-8 -*- #@Time :2017/11/24 4:40 #@Auther :liuzhenchuan #@File : ...
- 【智力题】IO——行测、笔试、面试中遇到的
昨天(05.23)下午去参加了明源软件的暑期实习宣讲+笔试,第一次听说这个行业,行业和笔试风格完全不一样啊,5道行测智力题+1个问答+ 斐波那契数列 + 洗牌算法(思想.流程图.代码),今年回来后线上 ...
- Visual studio 创建文件时自动添加备注
Visual studio 创建文件时自动添加备注 描述 要求每回添加一个类,普通类或单元测试类文件头自动添加备注, 比如:Copyright, FileName, Author and so on. ...
- Android笔记之获取debug.keystore和release.keystore的MD5/SHA1值
获取debug.keystore的key,如下图 获取release.keystore的key 输入命令keytool -list -v -keystore <jksFilename> 例 ...
- Action三种编写方式
1. 创建普通类不实现接口与继承类 2. 实现Action接口 3. 继承ActionSupport类(常用)