简单方法:

#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的更多相关文章

  1. 统计难题---hdu1251字典树模板

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1251 node *head=(node*)malloc(sizeof(node)); for(int ...

  2. (字典树模板)统计难题--hdu--1251

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1251 在自己敲了一遍后终于懂了,这不就用了链表的知识来建立了树,对!就是这样的,然后再查找 代码: #i ...

  3. hdu1251 统计难题

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=1251 题目: 统计难题 Time Limit: 4000/2000 MS (Java/Othe ...

  4. HDU1251 统计难题(Trie)

    统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others) Total Subm ...

  5. HDU1251统计难题(水字典树)

    统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others) Total Subm ...

  6. hdu1251(统计难题)

    这题就是一个字典树的模板题 统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Othe ...

  7. hdu1251统计难题(trie)

    统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others)Total Submi ...

  8. HDU-1251 统计难题,字典树或者map!

    统计难题 很久就看过这个题了,但不会~~~不会~~ 题意:给出一张单词表,然后下面有若干查询,每次给出一个单词,问单词表中是否存在以这个单词为前缀的单词,输出数量.本身也是自身的前缀.只有一组数据! ...

  9. HDU1251 统计难题 【trie树】

    统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others) Total Subm ...

随机推荐

  1. c/s 给 服务器上传文件(c/s和b/s互传文件)

    //c/s 代码 private void button1_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = ne ...

  2. BSGS算法及其扩展

    bsgs算法: 我们在逆元里曾经讲到过如何用殴几里得求一个同余方程的整数解.而\(bsgs\)就是用来求一个指数同余方程的最小整数解的:也就是对于\(a^x\equiv b \mod p\) 我们可以 ...

  3. pygame设置text和image共同显示

    下面介绍一下如何用pygame将text文本和图片一起绑定到视图 部分重点用不同颜色做了标记,希望对大家有帮助 代码块: %%writefile tranformtouxiang2.py import ...

  4. linux下比较两个文本文件的不同——diff命令

    1>Diff命令的功能Linux中Diff命令的功能为逐行比较两个文本文件,列出其不同之处.它对给出的文件进行系统的检查,并显示出两个文件中所有不同的行,不要求事先对文件进行排序. 2>语 ...

  5. 【转】利用URLConnection来发送POST和GET请求

    URL的openConnection()方法将返回一个URLConnection对象,该对象表示应用程序和 URL 之间的通信链接.程序可以通过URLConnection实例向该URL发送请求.读取U ...

  6. freemark简单事例

    工作准备:开发环境myeclipse freemarker.jar(需要下载) 首先引入freemarker.jar包.然后,,,,直接贴代码: 1.创建一个FreemarkerUtil类: pack ...

  7. Informatic学习总结_day03_update组件学习

  8. V$SQLAREA

    1.查看消耗资源最多的SQL: SELECT hash_value, executions, buffer_gets, disk_reads, parse_calls FROM V$SQLAREA W ...

  9. centos6.7环境半虚拟化软件xen及xm配置工具使用详解

    1.xen软件的安装及配置 环境准备: ①操作系统:centos6.7(注意最好使用centos6.7,centos6.5无法使用xen的图形化界面创建操作系统) ②调整虚拟机配置,内存4G(推荐2G ...

  10. 服务发现之consul的介绍、部署和使用

    什么是服务发现 微服务的框架体系中,服务发现是不能不提的一个模块.我相信了解或者熟悉微服务的童鞋应该都知道它的重要性.这里我只是简单的提一下,毕竟这不是我们的重点.我们看下面的一幅图片:     图中 ...