统计难题

【题目链接】统计难题

【题目类型】Trie

&题解:

Trie的模板题,只不过这题坑点在没给数据范围,改成5e5就可以过了,用的刘汝佳蓝书模板

&代码:

#include <cstdio>
#include <bitset>
#include <iostream>
#include <set>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long ll;
const int maxNode= 500000 +7,sigmaSize=26;
struct Trie
{
int ch[maxNode][sigmaSize],sz,val[maxNode];
Trie(){sz=1; memset(ch[0],0,sizeof(ch[0])); memset(val,0,sizeof(val));}
int idx(char c){return c-'a';}
void insert(char* s)
{
int u=0,n=strlen(s);
for(int i=0;i<n;i++){
int c=idx(s[i]);
if(!ch[u][c]){
memset(ch[sz],0,sizeof(ch[sz]));
ch[u][c]=sz++;
}
u=ch[u][c];
val[u]++;
}
}
int query(char* s)
{
int u=0,n=strlen(s);
for(int i=0;i<n;i++){
int c=idx(s[i]);
if(!ch[u][c]){
return 0;
}
u=ch[u][c];
}
return val[u];
}
}tr;
char s[23];
int main()
{
while(1){
gets(s);
int n=strlen(s);
if(n==0) break;
tr.insert(s);
}
while(gets(s)){
printf("%d\n",tr.query(s));
}
return 0;
}

HDU 1251 统计难题(Trie)的更多相关文章

  1. hdu 1251 统计难题 trie入门

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

  2. hdu 1251 统计难题(trie树入门)

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

  3. HDU - 1251 统计难题(trie树)

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

  4. HDU 1251 统计难题 (Trie)

    pid=1251">统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/ ...

  5. hdu 1251 统计难题(字典树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251 统计难题 Time Limit: 4000/2000 MS (Java/Others)    M ...

  6. HDU 1251 统计难题(Trie模版题)

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

  7. HDU 1251 统计难题 (字符串-Trie树)

    统计难题 Problem Description Ignatius近期遇到一个难题,老师交给他非常多单词(仅仅有小写字母组成,不会有反复的单词出现),如今老师要他统计出以某个字符串为前缀的单词数量(单 ...

  8. hdu 1251:统计难题[【trie树】||【map】

    <题目链接> 统计难题                        Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131 ...

  9. hdu 1251 统计难题 (字典树(Trie)<PS:C++提交不得爆内存>)

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

随机推荐

  1. java8集合--LinkedList纯源码

    package Queue; import java.util.*; import java.util.function.Consumer; /** * 双端队列主要实现list接口和Deque接口, ...

  2. JS弹出对话框的三种方式

    JS弹出对话框的三种方式 我们用到了alert()方法.prompt()方法.prompt()方法,都是在网页有一个弹出框,那么就让我们探究一下他们之间的区别: 一.第一种:alert()方法 < ...

  3. 如何用Eclipse+maven创建servlet 3.0 web 项目

    用eclipse + maven, 选择 maven-archetype-webapp,默认的servlet版本是2.3. 目前servlet版本都已经是3.X. 那有什么办法可以创建servlet ...

  4. Google 的 OKR 制度与KPI 有什么不同?

    https://mp.weixin.qq.com/s/aMGJvPPBA9d2uq8DOi3xFg

  5. Excel使用

    筛选 1.数据->取消\使用筛选; 边框 函数 1.使用函数的话需要设置单元格格式为常规;

  6. 关于struts中的表单元素- Form bean not specified on mapping for action: "helloa.do"报错

    今天测试struts时仿照书上写了一个小的表单提交代码 <html:form action="helloa.do" method="post"> & ...

  7. LeetCode 461 Hamming Distance 解题报告

    题目要求 The Hamming distance between two integers is the number of positions at which the corresponding ...

  8. 启动虚拟机提示"Units specified don’t exist SHSUCDX can’t install"

    新建虚拟机快速分区后启动报"Units specified don’t exist SHSUCDX can’t install",试过网上说的 修改BIOS设置方法不起作用 修改虚 ...

  9. pacakge-info.java

    翻看以前的笔记,看到一个特殊的java文件:pacakge-info.java,虽然有记录,但是不全,就尝试着追踪一下该问题, 分享一下流水账式的结果. 首先,它不能随便被创建.在Eclipse中, ...

  10. linux 拷贝软连接文件

    cp -s sourchfile targetfile 这样拷贝软连接文件时,会将其对应指定路径同步修改,即便原来的软连接是相对路径也不会有问题.