HDU 4287-Intelligent IME(哈希)
Intelligent IME
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2479 Accepted Submission(s): 1212
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.
1
3 5
46
64448
74
go
in
night
might
gn
3
2
0题意 :在手机键盘的背景下,给出一串数字,然后由这些数字能够枚举出一系列的字符串,然后给出一个字典,问这些字符串一共同拥有几个在字典中,逆向思考一下。一開始我是考虑着由给出的数字枚举出全部的可能的字符串然后在字典中一一查找,但时间复杂度太高了,后来看到题解才明确,字符串是能够转换成数字的。并且唯一相应,然后哈希一下就能够了。#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#define L long long
using namespace std;
const int INF=0x3f3f3f3f;
const int maxn=1000020;
int n,m,num[maxn],h[maxn];
char phone[]="22233344455566677778889999";
char word[5010][7];
int Binary_search(int x)
{
int mid,low=0,high=n-1;
while(low<=high)
{
mid=(low+high)/2;
if(num[mid]==x)
return mid;
else if(num[mid]>x)
high=mid-1;
else if(num[mid]<x)
low=mid+1;
}
return -1;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(h,0,sizeof(h));
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
scanf("%d",num+i);
for(int i=0;i<m;i++)
scanf("%s",word[i]);
vector <int> pos(num,num+n);
sort(num,num+n);
for(int i=0;i<m;i++)
{
int len=strlen(word[i]);
int sum=0;
for(int j=0;j<len;j++)
sum=sum*10+(phone[word[i][j]-'a']-'0');
int tem=Binary_search(sum);
if(tem!=-1)
h[num[tem]]++;
}
for(int i=0;i<n;i++)
printf("%d\n",h[pos[i]]);
}
return 0;
}
HDU 4287-Intelligent IME(哈希)的更多相关文章
- HDU 4287 Intelligent IME(map运用)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4287 Intellig ...
- HDU 4287 Intelligent IME(字典树数组版)
Intelligent IME Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4287 Intelligent IME hash
Intelligent IME Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...
- HDU 4287 Intelligent IME
Intelligent IME Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- ACM学习历程—HDU 4287 Intelligent IME(字典树 || map)
Description We all use cell phone today. And we must be familiar with the intelligent English input ...
- HDU 4287 Intelligent IME(string,map,stl,make_pair)
题目 转载来的,有些stl和string的函数蛮好的: //numx[i]=string(sx); //把char[]类型转换成string类型 // mat.insert(make_pair(num ...
- HDU 4287 Intelligent IME(字典树)
在我没用hash之前,一直TLE,字符串处理时间过长,用了hash之后一直CE,(请看下图)我自从经历我的字典树G++MLE,C++AC以后,一直天真的用C++,后来的CE就是因为这个,G++才支持这 ...
- Intelligent IME HDU - 4287 字典树
题意: 给你m个字符串,每一个字符对应一个数字,如下: 2 : a, b, c 3 : d, e, f 4 : g, h, i 5 : j, k, l 6 : m, n, o ...
- hdu Intelligent IME
算法:字典树 题意:手机9键拼音:2:abc 3:def 4:ghi 5:jkl 6:mno 7:pqrs 8:tuv 9:wxyz: 第一行读入一个T,代表测试组数: 之后输入两个整数n和m, 有 ...
随机推荐
- Linux下安装php环境并且配置Nginx支持php-fpm模块[www]
Linux下安装php环境并且配置Nginx支持php-fpm模块 http://www.cnblogs.com/freeweb/p/5425554.html 5分钟搭建 nginx +php --- ...
- Linux C程序异常退出怎么办——core文件帮你忙
Linux C程序异常退出怎么办——core文件帮你忙 http://blog.csdn.net/zhu2695/article/details/51512138
- 【Uva11762】Race to 1
模拟马尔可夫过程,具体看书. #include<bits/stdc++.h> #define N 1000010 using namespace std; ; void calcprime ...
- 【 VSFTPD 】ftp 客户端问题
网络环境: 两个独立的内网环境,前端都有路由和防火墙的管控.要在这两个独立的内网使用ftp通过互联网进行通信. 首先,ftp server 服务端口默认修改为:2100 数据端口修改为:21000 将 ...
- jquery.qrcode生成二维码支持中文
基本使用方法: 1.首先在页面中加入jquery库文件和qrcode插件. <script type="text/javascript" src="jquery.j ...
- Selenium2+python自动化66-装饰器之运行失败截图【转载】
前言 对于用例失败截图,很多小伙伴都希望在用例执行失败的时候能自动截图,想法是很好的,实现起来并不是那么容易. 这里分享下我的一些思路,当然目前还没找到完美的解决方案,我的思路是用装饰器去解决,希望有 ...
- 链式前向星写法下的DFS和BFS
Input 5 7 1 2 2 3 3 4 1 3 4 1 1 5 4 5 output 1 5 3 4 2 #include<bits/stdc++.h> using namespace ...
- 最小生成树(Minimum Spanning Tree)——Prim算法与Kruskal算法+并查集
最小生成树——Minimum Spanning Tree,是图论中比较重要的模型,通常用于解决实际生活中的路径代价最小一类的问题.我们首先用通俗的语言解释它的定义: 对于有n个节点的有权无向连通图,寻 ...
- 更新archlinux
有个上网本,虽然配置很差,但是安装的是arch,这不长时间不滚动更新出问题了, :: Proceed with installation? [Y/n] (/) checking keys % (/) ...
- 【找规律】Codeforces Round #392 (Div. 2) C. Unfair Poll
C. Unfair Poll time limit per test 1 second memory limit per test 256 megabytes input standard input ...