POJ2418——Hardwood Species(map映射)
Hardwood Species
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
题目大意:
给定一堆字符串,输出每个字符串出现的概率。
解题思路:
水题。用map<string,int>来存放每个字符串出现的次数。
注意:输出按字典序排序。
Code:
/*************************************************************************
> File Name: poj2418.cpp
> Author: Enumz
> Mail: 369372123@qq.com
> Created Time: 2014年10月26日 星期日 21时14分37秒
************************************************************************/ #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<list>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#define MAXN 100000
using namespace std;
map <string,int> m;
string Trie[MAXN];
int main()
{
int i=;
string tmp;
int k=;
int sum=;
while (getline(cin,tmp))
{
sum++;
m[tmp]++;
if (m[tmp]==)
Trie[k++]=tmp;
}
sort(Trie+,Trie+k);
for (int i=;i<k;i++)
{
cout<<Trie[i]<<" ";
double ret=(double)m[Trie[i]]*/(double)sum;
printf("%.4lf\n",ret);
}
return ;
}
POJ2418——Hardwood Species(map映射)的更多相关文章
- POJ2418 Hardwood Species—二叉查找树应用
1. Hardwood Species原题描述 Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 14326 Acce ...
- poj 2418 Hardwood Species (map)
题目:http://poj.org/problem?id=2418 在poj 上交题总是有各种错误,再次感叹各个编译器. c++ AC代码,G++为超时,上代码: #include<cstdio ...
- POJ-2418 Hardwood Species(二叉搜索树)
思路就是先将每个单词存进二叉树中,没出现一次,修改该单词所在结点的cnt++: 最后通过递归中序遍历输出结果. 思路很清晰,主要注意一下指针的使用,想一想为什么要这么用? 简单的解释就是,insert ...
- [ACM] POJ 2418 Hardwood Species (Trie树或map)
Hardwood Species Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 17986 Accepted: 713 ...
- 洛谷 UVA10226 Hardwood Species
洛谷 UVA10226 Hardwood Species 洛谷评测传送门 题目描述 PDF 输入格式 输出格式 输入输出样例 输入 #1复制 输出 #1复制 题目翻译: 给定若干字符串,输出格式为:( ...
- POJ 2418 Hardwood Species
Hardwood Species Time Limit: 10000MS Memory Limit ...
- Hardwood Species 分类: POJ 树 2015-08-05 16:24 2人阅读 评论(0) 收藏
Hardwood Species Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 20619 Accepted: 8083 De ...
- Hardwood Species(水)
Time Limit:10000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u SubmitStatus Descrip ...
- POJ 2418 ,ZOJ 1899 Hardwood Species - from lanshui_Yang
Description Hardwoods are the botanical group of trees that have broad leaves, produce a fruit or nu ...
随机推荐
- Poj 3982 序列
1.Link: http://poj.org/problem?id=3982 2.Content: 序列 Time Limit: 1000MS Memory Limit: 65536K Total ...
- Poj 3062 Celebrity jeopardy
1.Link: http://poj.org/problem?id=3062 2.Content: Celebrity jeopardy Time Limit: 1000MS Memory Lim ...
- jquery实现视觉滚动--fullpage
用fullpage.js实现视觉滚动效果 1.Html页面 <!DOCTYPE html> <html> <head> <meta charset=" ...
- android app widget 创建调用周期
1 ?Android widget 大小问题 2 ?RemoteViewService Android开发历程_15(AppWidget的使用) Appwidget就是手机应用中常常放在桌面(即hom ...
- DTCMS自定义标签,tags分割
DTcms.Web.UI\Label\article.cs /// <summary> /// 自定义:分割tags /// </summary> /// <param ...
- IE下的bug解决方案
1.IE6下的双边距bug <!DOCTYPE html> <html lang="en"> <head> <meta charset=& ...
- 51nod1265四点共面
1265 四点共面 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 给出三维空间上的四个点(点与点的位置均不相同),判断这4个点是否在同一个平面内(4点共线也算共面).如 ...
- 做了codility网站上一题:CountBoundedSlices
在写上一随笔之前,在Codility网站上还做了一个道题(非Demo题):CountBoundedSlices,得了60分(害臊呀).今天又重新做了一下这个算法,性能提高了不少,但由于此题不是Demo ...
- MySQL 5.5主从同步设置教程
先修改Master(10.1.123.197)的 my.cnf 配置 在 [mysqld] 中新增以下内容 log-bin=mysql-bin log-bin-index=mysql-bin.inde ...
- PowerDesigner 非数值默认值时会自动增加单引单
在PowerDesigner中,如果默认值是非数值型的,那么 PowerDesigner 会默认加上单引号 因此我们需要把这个默认的单引号干掉,如果是需要设置字符串默认值的时候,就手工加上 单引号 即 ...