HDU1251 统计难题
来源:互联网 发布:Python 加密算法 编辑:程序博客网 时间:2024/04/29 12:32
简单的字典树,当然也可以用其他方法。
#include<iostream>#include<algorithm>#include<string.h>#include<stdio.h>#include<math.h>#include<queue>using namespace std;#define nn 1001000#define lson l,mid,rt<<1#define rson mid+1,r,rt<<1|1struct Trie{ int ch[nn][26]; int val[nn]; int sz; Trie() { sz=1;memset(ch[0],0,sizeof(ch[0])); } int idx(char c) {return c-'a';} void insert(char *s,int v) { 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])); val[sz]=0; ch[u][c]=sz++; } u=ch[u][c]; val[u]+=v; } } int find(char *s) { int u,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]; }}t;int main(){ char s[20]; while(1) { gets(s); if(strcmp(s,"")==0) break; t.insert(s,1); } while(gets(s)) { int ans=t.find(s); printf("%d\n",ans); } return 0;}
0 0
- 统计难题 hdu1251
- HDU1251统计难题
- 统计难题 hdu1251
- HDU1251-统计难题
- 【统计难题】 hdu1251
- hdu1251统计难题
- hdu1251(统计难题)
- HDU1251:统计难题
- hdu1251统计难题
- HDU1251 统计难题
- hdu1251 统计难题 (Trie)
- hdu1251 统计难题 trie
- HDU1251-统计难题
- hdu1251 统计难题
- hdu1251-统计难题
- Hdu1251 统计难题
- hdu1251统计难题
- C++统计难题hdu1251
- DateFinition
- DateText1
- 强烈推荐android studio用的几个插件
- Android Studio开发JNI工程
- 腾讯云陈磊:解读腾讯海量产品之道
- HDU1251 统计难题
- 51nod 1001
- JavaScript学习笔记01
- 一寸照片变换背景色&操控变形
- C++错误
- jq选项卡&&js选项卡
- 阶乘计算
- 取给定正整数的指定bit位开始的指定长度的数据 将整数拆分成bit位表示的形式
- android开发代码之隐藏软键盘