hdu1251 统计难题 字典树
来源:互联网 发布:按option无法切换mac 编辑:程序博客网 时间:2024/05/20 14:26
字典树模板题
#include<iostream>#include<cstdio>using namespace std;struct point{ point* next[26]; int cot; //count how many prefixes from root to current point. point() //constructor method, initialize 26 child of pointer { cot = 0; memset(next,0,sizeof(next)); }};void insert(point *rt,char *s){ point p = rt; int i=0; int k; while(s[i]) { k = (s[i++]-'a'); if(p->next[k]==NULL) { p->next[k] = new point(); } p->next[k]->cot++; p = p->next; } return ;}int search(point *rt,char *s){ point p = rt; int i = 0; int k; while(s[i]) { k = s[i++]-'a'; if(p->next[k]==NULL) //the trie tree doesn't have the prefix { return 0; } } return p->next[k]->cot;}int main(){ point *rt = new point(); char s[25]; while(gets(s)!=NULL) { if(s[0]=='\0') break; cout<<s<<endl; insert(rt,s); } while(cin>>s) { cout<<search(rt,s)<<endl; } return 0;}注意 要用c++交,不然MLE,不知道为什么
0 0
- hdu1251 统计难题 字典树
- 【字典树】 hdu1251 统计难题
- hdu1251 统计难题(字典树)
- 统计难题(hdu1251字典树)
- hdu1251 统计难题 (字典树)
- HDU1251统计难题(字典树)
- hdu1251统计难题(字典树)
- Hdu1251 - 统计难题 - 字典树
- hdu1251 统计难题 【字典树】
- HDU1251 统计难题【字典树】
- 【字典树】HDU1251统计难题
- hdu1251 统计难题 字典树
- hdu1251 统计难题 字典树
- hdu1251统计难题+字典树
- HDU1251 统计难题【字典树】
- hdu1251 统计难题(字典树)
- hdu1251统计难题(字典树)
- HDU1251 统计难题 解题报告--字典树
- Masonry介绍与使用实践:快速上手Autolayout
- hdu5504 GT and sequence(BestCoder Round #60 )
- hdu5505(好题)
- 两个线程按特定时间顺序交替执行
- softMax(2)---predict实现
- hdu1251 统计难题 字典树
- 基站定位属性
- 网络获取json解析
- Linux vi指令详解
- Winpcap 链接 VS2013 小提示
- Insert & delte elements in doublely linked list
- JDBC-Java程序向mysql中插入数据的中文乱码
- Unity3d 协程、调用函数、委托
- 21.Plus One