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 ...
随机推荐
- 设置textview显示框内容不可编辑不可选择。
f1textview.allowsEditingTextAttributes=NO;////////////设置不可编辑不能用这个,得用下面的一个 textView.editable=NO;//设置可 ...
- zedboard之GPIO驱动(从FPGA一直到LINUX应用)
1 EDK 大家知道我们在EDK中建立GPIO然后倒出到SDK中,在SDK中可以用C语言操作外设GPIO,但是这还是裸机程序,没有用到LINUX.本文将记录从FPGA EDK生成GPIO一直到导入S ...
- .Net Core下如何管理配置文件(转载)
原文地址:http://www.cnblogs.com/yaozhenfa/p/5408009.html 一.前言 根据该issues来看,System.Configuration在.net core ...
- SQL允许远程访问
1.打开sqlserver对象资源管理器 右键 方面 常规 服务器配置 RemoteAccessEnabled true RemoteDacEnabled true 2.打开SQL SERVER管理 ...
- RxJava 平常使用
本文转载自: http://blog.csdn.net/theone10211024/article/details/50435325 一.Scheduler线程切换 这种场景经常会在“后台线程取数据 ...
- js实现雪花飘落效果的代码
使用js实现雪花飘落的效果,用html5绘布加js写的雪花飘效果 . 代码: <html> <head> <script> /** * js与html5实现的雪花飘 ...
- php判断ip黑名单程序代码
学校的新闻系统要求有些新闻只开放校内ip浏览,于是重写了一个代码来实现此功能,实现后的结果是,只要把允许访问的ip列入ip.txt这个文件中即可,同时支持c类ip,例如: ip.txt192.1682 ...
- WPF与DevExpress之旅-序言
随着.NET技术的发展,从之前的WINFORM转向到WPF是我们技术改革的必然趋势.WPF能给人带来震撼的视觉体验,也能更加规范我们的开发模式,与传统的WINFORM开发来说具有革命性的意义.DevE ...
- Teradata中fastload使用
Teradata Fastload Utility 是teradata数据库中一个基于命令行的快速load大量数据到一个空表的工具. 数据可以从以下途径被load: 1) Disk 或 tape; 2 ...
- 11、创建不使用XAML的WPF应用程序
首先新建一个空的项目,然后添加一个类,引用一下程序集: PresentationCore.dll PresentationFramework.dll WindowsBase.dll namespace ...