1、HDU 1251 统计难题  Trie树模板题,或者map

2、总结:用C++过了,G++就爆内存。。

题意:查找给定前缀的单词数量。

#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
#include<cstdio>
#define max(a,b) a>b?a:b
#define F(i,a,b) for(int i=a;i<=b;i++)
#define mes(a,b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
const int N=,MAX=; struct Node
{
int count;
Node *child[];
Node(){
mes(child,NULL);
count=;
}
}; Node *root=new Node,*current;
void insert(char *str)
{
current=root;
for(int i=;str[i];++i){
int m=str[i]-'a';
if(current->child[m]==NULL){
current->child[m]=new Node;
}
current=current->child[m];
current->count++;
}
} int search(char *str)
{
current=root;
for(int i=;str[i];++i){
int m=str[i]-'a';
if(current->child[m]==NULL)
return ;
current=current->child[m];
}
return current->count;
} int main()
{
char str[];
while(gets(str),*str)
insert(str);
while(gets(str))
printf("%d\n",search(str)); return ;
}

HDU 1251 Trie树模板题的更多相关文章

  1. HDU - 1251 字典树模板题

    Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己的前缀).  Input输入数据的第一部 ...

  2. hdu 1251 字典树模板题 ---多串 查找单词出现次数

    这道题题目里没有给定数据范围 我开了2005  疯狂的WA 然后开了50000, A掉  我以为自己模板理解错  然后一天没吃饭,饿得胃疼还是想着把这题A掉再去吃,谁知竟然是这样的问题,,,呵呵~~~ ...

  3. HDU 1251 统计难题 (Trie树模板题)

    题目链接:点击打开链接 Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单 ...

  4. poj3630 Phone List (trie树模板题)

    Phone List Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 26328   Accepted: 7938 Descr ...

  5. hdu 1251 trie树

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

  6. hdu 1754 线段树模板题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754 #include <cstdio> #include <cmath> # ...

  7. hdu 2665 划分树模板题(可作为模板)

    Kth number Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  8. 835. 字符串统计(Trie树模板题)

    维护一个字符串集合,支持两种操作: “I x”向集合中插入一个字符串x: “Q x”询问一个字符串在集合中出现了多少次. 共有N个操作,输入的字符串总长度不超过 105105,字符串仅包含小写英文字母 ...

  9. hihocoder_1014: Trie树(Trie树模板题)

    题目链接 #include<bits/stdc++.h> using namespace std; ; struct T { int num; T* next[]; T() { num=; ...

随机推荐

  1. vim配置方法

    /etc/vimrc (公共的) ~/.vimrc (私人的) rpm -qa|grep vim 这个命令,如何vim已经正确安装,则会显示上面三个包的名称 全部安装 yum -y install v ...

  2. [JavaCore] 不错的Java基础学习资料-持续更新

    容易弄混的JAVA基础知识: http://www.iteye.com/topic/943647 [总结]String in Java: http://www.iteye.com/topic/5221 ...

  3. office excel 装Visual Studio后报错解决方案

    安装完vs后,vs会向office安装COM加载项,但是在启动Excel时会发生弹出此加载项安装出错的消息,如下图. 名称: 从: file:///D:/Program Files (x86)/Mic ...

  4. FreeMarker学习(宏<#macro>的使用)

    原文链接:https://my.oschina.net/weiweiblog/blog/506301?p=1 用户定义指令-使用@符合来调用  有两种不同的类型:Macro(宏)和transform( ...

  5. xUtils,butterknife...处理findviewbyid

      在写android中,经常要出现大量的findviewbyid et_path = (EditText) findViewById(R.id.et_path); tv_info = (TextVi ...

  6. flex_宽度补全

    宽度40px,另一个的补全宽度: <!DOCTYPE html> <html lang="en"> <head> <meta charse ...

  7. background为圆角的表框,dp转Px,Px转dp

    圆角边框<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="ht ...

  8. 实现Web验证码图片-原理

    实现验证码的基础 GDI+ graphics device interface plus的缩写,即图形设备接口.GDI+为开发者提供了一组实现与各种设备(具有图形化能力但不涉及图形细节的设备)进行交互 ...

  9. PHP 生成二维码

    利用PHP QRcode生成二维码: php QRcode 官网 http://phpqrcode.sourceforge.net/ 在官网下载 phpqrcode.php就ok啦: 然后,查看自己的 ...

  10. 【转】Docker 常用命令

    转载: http://blog.csdn.net/zhang__jiayu/article/details/42611469   docker images:列出本地所有镜像 docker searc ...