POJ2418Hardwood Species
题意 : 输入若干个树木品种,里边有的是重复的,让你统计每个品种占输入的总数量的百分比,最后按字典序输出
思路 : 本题数量很大,所以采用直接统计的方式会超时,而采用的方法可以用二叉搜索树,或者用map函数或者是字典树都可以实现,呃,我想说,为什么用G++交WA了,得用C++交才对啊
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std ;
struct node
{
char name[] ;
struct node *lchild,*rchild ;
int count ;//记录该结点品种出现次数
}tree ;
struct node *root ;
int n = ;
void mid(struct node *root)
{
if(root != NULL)//按照中序遍历模式计算输出就是字典序
{
mid(root->lchild) ;
printf("%s %.4lf\n",root->name,((double)(root->count)/(n*1.0))*) ;
//输出单词和所占百分比
mid(root->rchild);
}
}
void insertBST(struct node **root,char *s)
{
if(*root == NULL)
{
struct node *p = (struct node *)malloc(sizeof(tree));
strcpy(p->name,s);//品种复制给新开辟的结点
p->lchild = NULL ;
p->rchild = NULL ;
p->count = ;
*root = p ;
}
else
{
if(strcmp(s,(*root)->name) == )//出现相同品种
{
((*root)->count)++ ;//该品种数加1,并不再重复插入
return;
}
else if(strcmp(s,(*root)->name) < )//如果插入单词小于当前结点单词
insertBST(&((*root)->lchild),s);//插入当前品种左子树
else insertBST(&((*root)->rchild),s);//否则插入右子树
}
}
int main()
{
char s[];
while(gets(s)!=NULL)
{
insertBST(&root,s);
n++ ;
}
mid(root) ;
return ;
}
http://www.cnblogs.com/fanminghui/p/3272141.html
会神用map写的,代码好短....
POJ2418Hardwood Species的更多相关文章
- 二叉排序树:POJ2418-Hardwood Species(外加字符串处理)
Hardwood Species Time Limit: 10000MS Memory Limit: 65536K Description Hardwoods are the botanical gr ...
- 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 ...
- POJ2418——Hardwood Species(map映射)
Hardwood Species DescriptionHardwoods are the botanical group of trees that have broad leaves, produ ...
- 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训练计划2418_Hardwood Species(Trie树)
解题报告 Tire树. #include <iostream> #include <cstring> #include <cstdio> #include < ...
- [ACM] POJ 2418 Hardwood Species (Trie树或map)
Hardwood Species Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 17986 Accepted: 713 ...
- POJ2418 Hardwood Species—二叉查找树应用
1. Hardwood Species原题描述 Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 14326 Acce ...
随机推荐
- Linux 伙伴算法简介
本文将简要介绍一下Linux内核中的伙伴分配算法. Technorati 标签: 伙伴算法 算法作用 它要解决的问题是频繁地请求和释放不同大小的一组连续页框,必然导致在已分配 ...
- 简单版解决IE兼容性问题
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> 在访问页面时, 如 ...
- iOS屏幕尺寸和分辨率
iOS平台家族成员主要包括iPhone.iPod Touch和iPad,但是各类设备的分辨率各不相同,目前存在的尺寸主要有: iOS设备的尺寸多种多样,此外,屏幕的分辨率也有多种,总结如下表所示: 其 ...
- C#简单的加密类
1.加密 public class EncryptHepler { // 验值 static string saltValue = "XXXX"; // 密码值 static st ...
- Silverlight中嵌套html、swf、pdf
1.MainPage.xaml <UserControl x:Class="SilverlightClient.MainPage" xmlns="http://sc ...
- 每日一“酷”之textwrap
介绍:需要美观打印时,可以使用textwrap模块来格式化要输出的文本,这个模块允许通过编程提高类似段落自动换行或填充特性等功能. 1 创建实例数据 sample_text = ''' I’m ver ...
- 绘制dot 图
常用参数 格式:dot -T<type> -o<outfile> <infile.dot> 输入文件是<infile.dot>,生成的格式由<ty ...
- 转学步园:jquery offset
JQuery Offset实验与应用 我们有时候需要实现这样一种功能:点击一个按钮,然后在按钮的下方显示一个div.当按钮位于角落时,div的位置设定就需要计算,使div完全显示. 我打算使用offs ...
- 2016 系统设计第一期 (档案一)MVC bootstrap model弹出子页面
通过bootstrap 弹出modal-dialog 子页面 ,例如我要弹出子页面:areaitem_sub_One.html. 具体步骤如下: 第一步:新建 areaitem_sub_One.ht ...
- 高精度计算的类(BigInteger和BigDecimal)
这两个类 在Java中没有对应的基本类型.不过,这两个类包含的方法,提供的操作与对基本类型所能执行的操作差不多. 也就是说,能对基本类型 int float 等的操作,也同样能作用于这两个类,只不过必 ...