搜索
热搜: NOIP OIer 神牛
查看: 360|回复: 0

3508

[复制链接]

主题

帖子

0

积分

新手上路

Rank: 1

积分
0
发表于 2023-5-22 20:19:18 | 显示全部楼层 |阅读模式
Hardwoods are the botanical groupof trees that have broad leaves, produce a fruit or nut, and generally godormant in the winter.
America's temperate climates produce forests withhundreds 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 40percent of the trees in the United States.

On the other hand, softwoods, or conifers, from the Latinword meaning "cone-bearing," have needles. Widely available USsoftwoods include cedar, fir, hemlock, pine, redwood, spruce and cypress. In ahome, the softwoods are used primarily as structural lumber such as 2x4s and2x6s, with some limited decorative applications.

Using satellite imaging technology, the Department ofNatural Resources has compiled an inventory of every tree standing on aparticular day. You are to compute the total fraction of the tree populationrepresented by each species.
输入
Input to your program consists ofa list of the species of every tree observed by the satellite; one tree perline. No species name exceeds 30 characters. There are no more than 10,000species and no more than 1,000,000 trees.
输出
Print the name of each speciesrepresented in the population, in alphabetical order, followed by thepercentage of the population it represents, to 4 decimal places.
样例输入1
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
样例输出1
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
提示/说明
This problem has huge input, usescanf instead of cin to avoid time limit exceeded.
标签
普及+/提高 其他 二叉搜索树,BST STL
下为翻译
硬木是一种植物,叶子宽大,能结果实或坚果,通常在冬天休眠。
美国的温带气候形成了数百种硬木的森林,这些树木具有某些共同的生物学特征。例如,尽管橡树、枫树和樱桃都是硬木,但它们是不同的物种。所有的硬木物种加起来占美国树木的40%。


另一方面,软木或针叶树,来自拉丁语,意思是“圆锥形”,有针叶。广泛可用的美国软木包括雪松、冷杉、铁杉、松树、红木、云杉和柏树。在家里,软木主要用作结构木材,如2x4和2x6,一些有限的装饰应用。


利用卫星成像技术,自然资源部编制了一份特定日期每棵树的清单。你要计算每个物种所代表的树木种群的总比例。
这道题需要用到map工具
下为map头文件语句
代码:
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4.     map<string,int>m1;//定义一个map
  5. //自动建立Key -value的对应。key 和value可以是任意你需要的类型。
  6. //map是STL的一个关联容器,它提供一对一的hash。
  7. //第一个可以称为关键字(key),每个关键字只能在map中出现一次;
  8. //第二个可能称为该关键字的值(value);
  9.     int c=0;//总次数
  10.     string s;//输入字符串
  11.     while(getline(cin,s)){//getline接收空格
  12.         m1[s]++;//类似hash,记录s的出现次数
  13.         c++;//总个数加1,以便取百分数
  14.     }
  15.     map<string,int>::iterator i;//这条语句定义了一个名为i的变量,它的数据类型是由map<string,int>定义的iterator类型
  16.     for(i=m1.begin();i!=m1.end();i++) {//也就是每个种类都遍历到了,并且不重复,自动字母序,按字母序遍历
  17.         //m1.begin():字母序首项
  18.         //m1.end():字母序末项
  19.         //i->first:树的名称
  20.         //i->end:树的类别
  21.         cout<<fixed<<setprecision(4)<<i->first<<" "<<100.0*(i->second)/c<<'\n';//输出树的名称,百分数
  22.     }
  23.     return 0;
  24. }
复制代码


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

津ICP备19006949号-1 | 津公网安备12010102000465号

快速回复 返回顶部 返回列表