hdu-1800
思路:
这题被坑的不轻。
首先花了一段时间想明白了思路是要找出现次数最多数字,以为这题就这样解决了,结果发现每个数字的最大长度是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的更多相关文章
- --hdu 1800 Flying to the Mars(贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1800 Ac code: #include<stdio.h> #include<std ...
- hdu 1800 (map)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1800 Flying to the Mars Time Limit: 5000/1000 MS (Java/ ...
- HDU - 1800 Flying to the Mars 【贪心】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1800 题意 给出N个人的 level 然后 高的level 的 人 是可以携带 比他低level 的人 ...
- HDU 1800 Flying to the Mars 字典树,STL中的map ,哈希树
http://acm.hdu.edu.cn/showproblem.php?pid=1800 字典树 #include<iostream> #include<string.h> ...
- HDU 1800 Flying to the Mars Trie或者hash
http://acm.hdu.edu.cn/showproblem.php?pid=1800 题目大意: 又是废话连篇 给你一些由数字组成的字符串,判断去掉前导0后那个字符串出现频率最高. 一开始敲h ...
- Hdu 1800 字符串hash
题目链接 题意: 给出n(n<=3000)个字符串(长度<30,数字组成,肯能存在前导0), 问该序列最少可以分成多少个单调序列.可以转化成求相同字符串的个数的最大值 附上代码: /*** ...
- hdu 1800 Flying to the Mars(简单模拟,string,字符串)
题目 又来了string的基本用法 //less than 30 digits //等级长度甚至是超过了int64,所以要用字符串来模拟,然后注意去掉前导零 //最多重复的个数就是答案 //关于str ...
- hdu 1800 Flying to the Mars
Flying to the Mars 题意:找出题给的最少的递增序列(严格递增)的个数,其中序列中每个数字不多于30位:序列长度不长于3000: input: 4 (n) 10 20 30 04 ou ...
- HDU 1800——Flying to the Mars——————【字符串哈希】
Flying to the Mars Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- HDU 1800 hash 找出现最多次数的字符串的次数
乘法hash: 这类hash函数利用了乘法的不相关性 int Hash(char *str){ int seed = 131 , value=0; while(*str != '\0'){ ...
随机推荐
- [AngularJS] ngMessageFormat
ngMessageFormat can be installed via npm using the following command: $ npm install angular-message- ...
- 如何查看linux系统下的各种日志文件 linux 系统日志的分析大全
日志分类: 1. 连接时间的日志 连接时间日志一般由/var/log/wtmp和/var/run/utmp这两个文件记录,不过这 两个文件无法直接cat查看,并且该文件由系统自动更新,可以通过如下: ...
- Code First研究学习1_Reverse Enginner Code First
最近因为公司需要,自己开始研究Code First,之前还是听说过这个,也知道是代码优先的意思!至于具体怎么的代码优先,我的理解如下! 在听说code first的时候,心里也就觉得怪了,是怎么将M ...
- Ehcache入门(一)——开发环境的搭建
EhCache 是一个纯Java的进程内缓存框架,具有快速.精干等特点,是Hibernate中默认的CacheProvider. 那么.如何搭建Ehcache的开发环境呢? 1.下载相关的jar包,这 ...
- mongodb安装服务
一.准备工作 1:下载: http://www.mongodb.org/downloads 2:解压到ZIP到 D:\Mongodb ,在此目录下再建立2个目录 D:\Mongodb\db和D ...
- 转载:Struts2.3.15.1升级总结
转载网址:http://blog.csdn.net/amosryan/article/details/10350481 由于大家都懂的原因,涉struts2的项目需要将struts2相关包升级至2.3 ...
- Oracle database启动过程分析
实例跟数据库的区别 实例(instance)是内存中的一块区域和一组后台进程的集合.它的作用是维护数据库文件的.而数据库(database)则是指存放数据的数据库文件.它是一系列格式化的数据的集合.它 ...
- C语言编程的进制问题问题
在我们的编译器,我用的是ADS 开发平台,现在RTC模块编程时,2410作为上位机,如下代码: n = rBCDDATE;if(n==1) time->day =0x31 ; 波斯历的日期与 ...
- 搭建本地Nuget服务器并使用NuGet Package Explorer工具打包nuget包
1.什么是Nuget: 百度百科描述: Nuget是 ASP .NET Gallery 的一员.NuGet 是免费.开源的包管理开发工具,专注于在 .NET 应用开发过程中,简单地合并第三方的组件库. ...
- NUMBER BASE CONVERSION(进制转换)
Description Write a program to convert numbers in one base to numbers in a second base. There are 62 ...