HDU 4287 Intelligent IME(字典树)
来源:互联网 发布:冒险岛自由市场数据 编辑:程序博客网 时间:2024/04/27 13:41
题意:给你几串数字,每一串数字都是拼音九键的按键顺序。再给你几个单词,问你从刚才的按键顺序中分别能按出多少个给定的单词。
思路:用map直接将每个字母映射为拼音九键对应的数字,再插入到字典树,插入完后对应位置u的v[u]+1,v[u]表示打到u这个位置能打出的给定的单词的单词数。总体来说还是比较简单的。
AC代码:
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<string>
#include<queue>
#include<vector>
#include<map>
using namespace std;
const int mx=1000005;
const int inf=0x3f3f3f3f;
int num,cas,n,m,T;
map<char,int> mp;
struct node{
int ch[mx][10];
int v[mx];
int sz;
void add(char *s)
{
int u=0,n=strlen(s);
for(int i=0;i<n;i++)
{
int id=mp[s[i]];
if(ch[u][id]==0)
{
ch[u][id]=sz;
v[sz]=0;
memset(ch[sz],0,sizeof(ch[sz]));
sz++;
}
u=ch[u][id];
}
v[u]++;
}
void find(char *s)
{
int u=0,n=strlen(s);
for(int i=0;i<n;i++)
{
int id=s[i]-'0';
if(ch[u][id]==0) {printf("0\n");return;}
u=ch[u][id];
}
printf("%d\n",v[u]);
}
void init(){
memset(ch[0],0,sizeof(ch[0]));
v[0]=0;
sz=1;
mp['a']=2;mp['b']=2;mp['c']=2;mp['d']=3;mp['e']=3;mp['f']=3;
mp['g']=4;mp['h']=4;mp['i']=4;mp['j']=5;mp['k']=5;mp['l']=5;
mp['m']=6;mp['n']=6;mp['o']=6;mp['p']=7;mp['q']=7;mp['r']=7;mp['s']=7;
mp['t']=8;mp['u']=8;mp['v']=8;mp['w']=9;mp['x']=9;mp['y']=9;mp['z']=9;
}
}a;
int main()
{
//ios::sync_with_stdio(false);
cas=0;
char c[5005][10];
char s[65];
while(scanf("%d",&T)!=EOF)
{
while(T--)
{
a.init();
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%s",c[i]);
for(int i=1;i<=m;i++) {
scanf("%s",s);
a.add(s);
}
for(int i=1;i<=n;i++)
a.find(c[i]);
}
}
return 0;
}
- HDU 4287 Intelligent IME(字典树)
- HDU 4287 Intelligent IME(字典树)
- Hdu 4287 Intelligent IME 字典树 Hash
- hdu 4287 Intelligent IME (字典树)
- [字典树] HDU 4287 - Intelligent IME
- hdu 4287 Intelligent IME (字典树)
- HDU 4287 Intelligent IME (字典树 && map)
- hdu 4287 Intelligent IME 字典树
- HDU - 4287 Intelligent IME 字典树
- HDU-4287 Intelligent IME (Trie 字典树 入门题)
- hdoj 4287 Intelligent IME 字典树
- hdu 4287 Intelligent IME
- HDU-4287-Intelligent IME
- HDU 4287 Intelligent IME
- hdu 4287 Intelligent IME
- Intelligent IME hdu 4287
- HDU 4287 Intelligent IME
- HDU 4287 Intelligent IME
- [基础题] 7.第二种(*)按如下要求编写Java程序:
- 费用流-模板
- 自动人机无脑3v3脚本
- 高德地图的多人定位实现方式
- Hibernate的关联关系
- HDU 4287 Intelligent IME(字典树)
- markdown简单语法总结
- Visual->UIElement->FrameworkElement,带来更多功能的同时也带来了更多的限制
- sleep()与wait()方法的区别
- shadowsocks ubuntu 安装
- (一)初始electron
- 动态规划问题分析求解
- 个人编程娱乐小游戏--三子棋
- mysql高性能笔记-schema与数据类型一