hdu 4287Intelligent IME(简单hash)
Intelligent IME
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1810 Accepted Submission(s): 897
2 : a, b, c 3 : d, e, f 4 : g, h, i 5 : j, k, l 6 : m, n, o
7 : p, q, r, s 8 : t, u, v 9 : w, x, y, z
When we want to input the word “wing”, we press the button 9, 4, 6, 4, then the input method will choose from an embedded dictionary, all words matching the input number sequence, such as “wing”, “whoi”, “zhog”. Here comes our question, given a dictionary, how many words in it match some input number sequences?
Two integer N (1 <= N <= 5000), M (1 <= M <= 5000), indicating the number of input number sequences and the number of words in the dictionary, respectively. Then comes N lines, each line contains a number sequence, consisting of no more than 6 digits. Then comes M lines, each line contains a letter string, consisting of no more than 6 lower letters. It is guaranteed that there are neither duplicated number sequences nor duplicated words.
3 5
46
64448
74
go
in
night
might
gn
2
0
题目意思就不多说了,将下面的字符串hash映射到上面的数字上即可。
#include<iostream>
#include<cstring>
using namespace std;
int hash1[1000005];
int a[5005];
char b[5005][8]; int cal(char *s)
{
int tmp=0;
int len=strlen(s),i;
for(i=0;i<len;i++)
{
if(s[i]>='a'&&s[i]<='c') tmp=tmp*10+2;
else if(s[i]>='d'&&s[i]<='f') tmp=tmp*10+3;
else if(s[i]>='g'&&s[i]<='i') tmp=tmp*10+4;
else if(s[i]>='j'&&s[i]<='l') tmp=tmp*10+5;
else if(s[i]>='m'&&s[i]<='o') tmp=tmp*10+6;
else if(s[i]>='p'&&s[i]<='s') tmp=tmp*10+7;
else if(s[i]>='t'&&s[i]<='v') tmp=tmp*10+8;
else if(s[i]>='w'&&s[i]<='z') tmp=tmp*10+9;
}
return tmp;
} int main()
{
int tes,i;
cin>>tes;
while(tes--)
{
int n,m;
cin>>n>>m;
for(i=0;i<n;i++)
cin>>a[i]; //存放数字
for(i=0;i<m;i++)
cin>>b[i];
memset(hash1,0,sizeof(hash1));
for(i=0;i<m;i++)
hash1[cal(b[i])]++;
for(i=0;i<n;i++)
cout<<hash1[a[i]]<<endl;
}
return 0;
} //406MS
hdu 4287Intelligent IME(简单hash)的更多相关文章
- HDU 4287-Intelligent IME(哈希)
Intelligent IME Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 2085 核反应堆 --- 简单递推
HDU 2085 核反应堆 /* HDU 2085 核反应堆 --- 简单递推 */ #include <cstdio> ; long long a[N], b[N]; //a表示高能质点 ...
- HDOJ-ACM1425 sort 简单hash应用
其实快排也可以通过这个问题~不是考点 没想到考点是这个,简单hash应用,空间换时间 初始化一个长度为1000001的数组(由于数字的范围为[-500000,500000]) 如果存在这个数m,数组下 ...
- Least Common Multiple (HDU - 1019) 【简单数论】【LCM】【欧几里得辗转相除法】
Least Common Multiple (HDU - 1019) [简单数论][LCM][欧几里得辗转相除法] 标签: 入门讲座题解 数论 题目描述 The least common multip ...
- 七夕节 (HDU - 1215) 【简单数论】【找因数】
七夕节 (HDU - 1215) [简单数论][找因数] 标签: 入门讲座题解 数论 题目描述 七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:"你们想知道你们 ...
- HDU 1880 简单Hash
题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=1880] 中文题面,题意很简单: 题解: 把每个 魔咒 和 对应的功能分别Hash,然后分别映射到ma ...
- HDU——2112HDU Today(SPFA+简单Hash或map+前向星)
HDU Today Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 4821 String (HASH)
题意:给你一串字符串s,再给你两个数字m l,问你s中可以分出多少个长度为m*l的子串,并且子串分成m个长度为l的串每个都不完全相同 首先使用BKDRHash方法把每个长度为l的子串预处理成一个数字, ...
- hdu 4622 Reincarnation 字符串hash 模板题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4622 题意:给定一个长度不超过2000的字符串,之后有不超过1e5次的区间查询,输出每次查询区间中不同 ...
随机推荐
- 简单机器学习人脸识别工具face-recognition python小试,一行代码实现人脸识别
摘要: 1行代码实现人脸识别,1. 首先你需要提供一个文件夹,里面是所有你希望系统认识的人的图片.其中每个人一张图片,图片以人的名字命名.2. 接下来,你需要准备另一个文件夹,里面是你要识别的图片.3 ...
- RxSwift 系列(九)
前言 看完本系列前面几篇之后,估计大家也还是有点懵逼,本系列前八篇也都是参考RxSwift官方文档和一些概念做的解读.上几篇文章概念性的东西有点多,一时也是很难全部记住,大家脑子里面知道有这么个概念就 ...
- Can you find it? HDU - 2141 (二分查找)
Give you three sequences of numbers A, B, C, then we give you a number X. Now you need to calculate ...
- appcompat_v7怎么不创建
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha 我们建项目时直接把最小SDK选在Android4.0以上不就不需要这个支持库
- JZYZOJ1261 字典序最小的lis
http://172.20.6.3/Problem_Show.asp?id=1261 求字典序方法: f[i]表示i位数字的最长上升子序列长度,len为最长上升子序列长度,ans[t]为第t位答案 ...
- hdu 1171 多重背包
题意:给出价值和数量,求能分开的最近的两个总价值,例如10,20*2,30,分开就是40,40 链接:点我 #include<cstdio> #include<iostream> ...
- bzoj 1458: 士兵占领 -- 最大流
1458: 士兵占领 Time Limit: 10 Sec Memory Limit: 64 MB Description 有一个M * N的棋盘,有的格子是障碍.现在你要选择一些格子来放置一些士兵 ...
- 使用SQL语句将数据库中的两个表合并成一张表
select * into 新表名 from (select * from T1 union all select * from T2) 这个语句可以实现将合并的数据追加到一个新表中. 不合并重复数 ...
- Java容器-引用数据类型排序+TreeSet、TreeMap底层实现
目录 1.冒泡排序的实现 2.比较接口(普通数据类型.引用数据类型) 普通数据类型:冒泡排序 引用数据类型:包装类(Integer.String.Character.Date) 自定义类型:实体类:i ...
- RFID Reader ICs
http://www.advanide.com/readeric.htm Low Frequency Reader ICs Manufacturer Product Frequency ISO Com ...