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 ...
随机推荐
- WP开发笔记——WP APP添加页面跳转动画
微软的toolkit团队为我们为我们提供了这样一套组件,叫做TransitionServices服务. 简单说一下它具备的效果: turnstile(轴旋转效果): turnstile feather ...
- Entity Framework Code First 常用方法集成
using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using S ...
- C#中Split函数的使用
Split函数 描述 :返回一个下标从零开始的一维数组,它包含指定数目的子字符串. 语法 :Split(expression[, delimiter[, count[, compare]] ...
- JavaScript 垃圾回收机制分析
同C# .Java一样可以手工调用垃圾回收程序,但是由于其消耗大量资源,而且手工调用的不会比浏览器判断的准确,所以不推荐手工调用垃圾回收. 最近精力主要用在了Web 开发上,读了一下<Jav ...
- RTC搭建android下三层应用程序访问服务器MsSql-客户端
android下stringgrid已知问题: 通过点击时获取对应行的值有问题,在win下调试正常,在android下出现定位不准 二.客户端开发 1,新建工程 2,添加相关客户端控件TRtcHttp ...
- 获取枚举Description的Name
/// <summary> /// 获取枚举Description的Name /// </summary> /// <param name="enumName& ...
- Git客户端Windows下的使用
1,必须安装的软件 msysgit http://code.google.com/p/msysgit/downloads/list?q=full+installer+official+git (ms ...
- 轻量级远程调用框架-Hessian学习笔记-Demo实现
Hessian是一个轻量级的remoting onhttp工具,使用简单的方法提供了RMI的功能. 相比WebService,Hessian更简单.快捷.采用的是二进制RPC协议,因为采用的是二进制协 ...
- C#模拟键盘鼠标事件 SendKeys 的特殊键代码表(转)
使用 SendKeys 将键击和组合键击发送到活动应用程序.此类无法实例化.若要发送一个键击给某个类并立即继续程序流,请使用 Send.若要等待键击启动的任何进程,请使用 SendWait. 每个键都 ...
- mysql5.5 Replication 主从同步
mysql5.5 Replication 主从同步 ------------------[主]------------------[mysqld]server-id=1 log-bin=mysql-b ...