思路:

这题被坑的不轻。

首先花了一段时间想明白了思路是要找出现次数最多数字,以为这题就这样解决了,结果发现每个数字的最大长度是30,long long都装不下,因此就要用字符串来保存处理。然后在insert的时候进行一下计数就可以了

最关键的地方是struct内的构造函数中,在初始化next数组的时候,一定要面面俱到!不然漏掉哪个,如果没有初始化,就相当于为空指针,就会出现内存泄露,就因为这点被卡了好久。

AC代码:

#include <iostream>
#include <cstring>
#define max(a,b) (a)>(b)?(a):(b)
using namespace std; struct node
{
int e;
node* next[];
node():e(){
for(int i = ;i <= ;i++)
next[i] = ;
}
};
node* root;
int ans; void insert(char* s)
{
int n;
node* p = root;
for(;*s!='\0';s++)
{
n = *s-'';
if(p->next[n] == )
p->next[n] = new node();
p = p->next[n];
}
p->e++;
ans = max(ans,p->e);
} int main()
{
int j;
int n;
while(cin>>n)
{
ans = ;
root = new node();
char str[];
for(int i = ;i <= n;i++) {
cin>>str;
for(j = ;j < strlen(str);j++)
if(str[j] != '')
break;
insert(&str[j]);
}
cout<<ans<<endl;
}
return ;
}

hdu-1800的更多相关文章

  1. --hdu 1800 Flying to the Mars(贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1800 Ac code: #include<stdio.h> #include<std ...

  2. hdu 1800 (map)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1800 Flying to the Mars Time Limit: 5000/1000 MS (Java/ ...

  3. HDU - 1800 Flying to the Mars 【贪心】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1800 题意 给出N个人的 level 然后 高的level 的 人 是可以携带 比他低level 的人 ...

  4. HDU 1800 Flying to the Mars 字典树,STL中的map ,哈希树

    http://acm.hdu.edu.cn/showproblem.php?pid=1800 字典树 #include<iostream> #include<string.h> ...

  5. HDU 1800 Flying to the Mars Trie或者hash

    http://acm.hdu.edu.cn/showproblem.php?pid=1800 题目大意: 又是废话连篇 给你一些由数字组成的字符串,判断去掉前导0后那个字符串出现频率最高. 一开始敲h ...

  6. Hdu 1800 字符串hash

    题目链接 题意: 给出n(n<=3000)个字符串(长度<30,数字组成,肯能存在前导0), 问该序列最少可以分成多少个单调序列.可以转化成求相同字符串的个数的最大值 附上代码: /*** ...

  7. hdu 1800 Flying to the Mars(简单模拟,string,字符串)

    题目 又来了string的基本用法 //less than 30 digits //等级长度甚至是超过了int64,所以要用字符串来模拟,然后注意去掉前导零 //最多重复的个数就是答案 //关于str ...

  8. hdu 1800 Flying to the Mars

    Flying to the Mars 题意:找出题给的最少的递增序列(严格递增)的个数,其中序列中每个数字不多于30位:序列长度不长于3000: input: 4 (n) 10 20 30 04 ou ...

  9. HDU 1800——Flying to the Mars——————【字符串哈希】

    Flying to the Mars Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  10. HDU 1800 hash 找出现最多次数的字符串的次数

    乘法hash: 这类hash函数利用了乘法的不相关性 int Hash(char *str){    int seed = 131 , value=0;    while(*str != '\0'){ ...

随机推荐

  1. Spring事务管理使用

    发现问题 最近,碰到一个问题,再用spring实现事务管理的时候,发现不起作用,在出异常时,并不会回滚数据库操作. 我想实现的功能如下: @Transactional(isolation=Isolat ...

  2. Unix C++(boost) 线程同步和线程组

    #include <boost/thread.hpp> #include <iostream> #include <vector> #include <cst ...

  3. XgCalendar日历插件动态添加参数

    在使用xgcalendar日历插件的时候,参数数组并非只有类型.显示时间.时区等这些参数,还可以根据extParam自定义参数扩展搜索条件,例如根据用户Id搜索不同用户的日历信息,需要将用户的Id存在 ...

  4. yii console.php 报错 Property "CConsoleApplication.theme" is not defined.

    默认配置的话,是不会出现这个错误的,应该是有人为修改了 yiic.php 这个文件,本来是 $config 载入的应该是 console.php ,人为修改后载入了 main.php 这个配置文件了 ...

  5. 根据goodsId获得相关商品的列表

    List<Goods> goodsList = goodsDetailService.getGoodsListByproductId(productId); for (Goods good ...

  6. MVP模式 详解 案例

    介绍 MVC: View:对应于布局文件 Model:业务逻辑和实体模型 Controllor:对应于Activity 实际上关于该布局文件中的数据绑定的操作,事件处理的代码都在Activity中,造 ...

  7. codevs 1733 聪明的打字员 (Bfs)

    /* Bfs+Hash 跑的有点慢 但是codevs上时间限制10s 也ok */ #include<iostream> #include<cstdio> #include&l ...

  8. innodb的innodb_buffer_pool_size和MyISAM的key_buffer_size

    一. key_buffer_size 对MyISAM表来说非常重要. 如果只是使用MyISAM表,可以把它设置为可用内存的 30-40%.合理的值取决于索引大小.数据量以及负载 -- 记住,MyISA ...

  9. 如何在github上传自己的项目

    1.首先在github创建自己的账号. 2.下载github for windows 客户端 (备注:这里我的电脑是windows系统的) ,不要下载错了,网上下载的应该是这样的安装程序 3.安装gi ...

  10. 解决CENTOS7虚拟机更改静态IP无法启动

    在linuxman的编辑中,未出现问题.反复的查看原因未果,后查明是虚拟机所致.1.在开启网络时,有错误提示:Restarting network (via systemctl):  Job for ...