统计难题 HDU1251
简单方法:
#include<bits/stdc++.h>
using namespace std; int main()
{
char s[];
map<string,int>ma;
while(gets(s)&&strlen(s)!=)
{
for(int i=strlen(s)-;i>=;i--)
{ ma[s]++;
s[i]='\0';
// cout<<s<<endl;
} }
while(gets(s))
{
printf("%d\n",ma[s]); } }
但是当数据过多的时候map就不行了
要用新的数据结构——字典树
有两种实现的方法 一种是指针 一种是数组
数组的实现方法更为方便 高明 快速
注意 数组一定要开到一百万 不然wa !!!
#include<bits/stdc++.h>
using namespace std;
int trie[][]={};
int sum[]={};
int pos=; void insert1( char *word )
{
int root=;
for(int i=;i<strlen(word);i++)
{ int ch=word[i]-'a';
if(trie[root][ ch ]==)
trie[root][ ch ]=++pos;
root=trie[root][ch];
sum[root]++;
} } int find1(char *word)
{
int root=;
for(int i=;i<strlen(word);i++)
{
int ch=word[i]-'a';
if(trie[root][ ch ]==)return ;
root=trie[root][ch]; }
return sum[root]; } int main()
{
char word[];
while(gets(word))
{
if(strlen(word)==)break; insert1(word); }
while(gets(word))
{
printf("%d\n",find1(word));
} }
统计难题 HDU1251的更多相关文章
- 统计难题---hdu1251字典树模板
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1251 node *head=(node*)malloc(sizeof(node)); for(int ...
- (字典树模板)统计难题--hdu--1251
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1251 在自己敲了一遍后终于懂了,这不就用了链表的知识来建立了树,对!就是这样的,然后再查找 代码: #i ...
- hdu1251 统计难题
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=1251 题目: 统计难题 Time Limit: 4000/2000 MS (Java/Othe ...
- HDU1251 统计难题(Trie)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Total Subm ...
- HDU1251统计难题(水字典树)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Total Subm ...
- hdu1251(统计难题)
这题就是一个字典树的模板题 统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Othe ...
- hdu1251统计难题(trie)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- HDU-1251 统计难题,字典树或者map!
统计难题 很久就看过这个题了,但不会~~~不会~~ 题意:给出一张单词表,然后下面有若干查询,每次给出一个单词,问单词表中是否存在以这个单词为前缀的单词,输出数量.本身也是自身的前缀.只有一组数据! ...
- HDU1251 统计难题 【trie树】
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Total Subm ...
随机推荐
- java程序在windows后台执行的办法
1.新建run.txt文件 2.在文件中输入一下内容: @echo off start javaw -jar xx.jar exit 3.保存,修改文件名为run.bat4.双击即可 5.删除wind ...
- python基础知识~logger模块
一 配置文件模块 import logging ->导入模块 logger = logging.getLogger('mylogger') ->初始化类二 创建句柄 1 文件句柄 fh = ...
- python 数据类型详解
python数据类型详解 参考网址:http://www.cnblogs.com/linjiqin/p/3608541.html 目录1.字符串2.布尔类型3.整数4.浮点数5.数字6.列表7.元组8 ...
- 2017-2018-2 20155303 『网络对抗技术』Exp3:免杀原理与实践
2017-2018-2 20155303 『网络对抗技术』Exp3:免杀原理与实践 --------CONTENTS-------- 1. 免杀原理与实践说明 实验说明 基础问题回答 2. 使用msf ...
- numpy中 array数组的shape属性
numpy.array 的shape属性理解 在码最邻近算法(K-Nearest Neighbor)的过程中,发现示例使用了numpy的array数组管理,其中关于array数组的shape(状态)属 ...
- 技巧:Vim 的纵向编辑模式【转】
转自:https://www.ibm.com/developerworks/cn/linux/l-cn-vimcolumn/ 张 曜民 和 卢 丹2011 年 2 月 18 日发布 WeiboGoog ...
- 汇编语言转换成c语言,或者汇编语言转换成golang的汇编,c语言转换成golang的方法
https://github.com/minio/c2goasm http://microapl.com/asm2c/index.html 收费的 https://gith ...
- Python3学习笔记10-条件控制
Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块 var1 = 100 if var1: print("1 - if 表达式条件为 true&q ...
- 高级 Java 面试通关知识点整理!
1.常用设计模式 单例模式:懒汉式.饿汉式.双重校验锁.静态加载,内部类加载.枚举类加载.保证一个类仅有一个实例,并提供一个访问它的全局访问点. 代理模式:动态代理和静态代理,什么时候使用动态代理. ...
- git 的入门使用到团队协作
1.git 的安装.下载---安装,esay. 下载地址:https://git-for-windows.github.io/ 2.创建一个自己的身份 git config --global user ...