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, 有 ...
随机推荐
- classNotFound修复
万恶的这个bug,也是经常遇见,每一次都是在反复检查完代码之后并没有发现错误,然后开始上网百度,发现也并没有一个准确的解答.在此给出我的个人的修复bug的过程. 1.首先我是遇到了找不到entity中 ...
- 【bzoj2242】计算器
#include<bits/stdc++.h> #define inf 1000000000 using namespace std; typedef long long ll; ?a:g ...
- 【 Python 】函数的参数
一.默认参数: 默认参数可以简化函数的调用,设置默认参数时,有几点要注意: 1,必选参数在前,默认参数在后,否则python的解释器会报错. 2,如何设置默认参数. 当函数有多个参数时,把变化大的参数 ...
- django框架实现restful风格的API开发
RESTful风格的要求:https://www.cnblogs.com/chichung/p/9933116.html 利用django原生的框架直接做RESTful的API开发是怎样的呢?感受一下 ...
- Ubuntu 18.04 sublime text 3176 安装、汉化及配置中文输入
转载自:https://blog.csdn.net/weixin_42508385/article/details/82152393 一.下载: 在https://www.sublimetext.co ...
- python通过多进程实行多任务
#原创,转载请联系 在开始之前,我们要知道什么是进程.道理很简单,你平时电脑打开QQ客户端,就是一个进程.再打开一个QQ客户端,又是一个进程.那么,在python中如何用一篇代码就可以开启几个进程呢? ...
- Spring MVC基础篇4
Spring MVC操作原生Servlet 对象 Spring MVC 可以操作原生的Servlet API,如下的这些原生API,可以各自 自由混合使用,也可以和其他非原生 参数组合使用 实例代码: ...
- 描述一下JVM加载class文件的原理机制
Java中的所有类,都需要由类加载器装载到JVM中才能运行.类加载器本身也是一个类,而它的工作就是把class文件从硬盘读取到内存中.在写程序的时候,我们几乎不需要关心类的加载,因为这些都是隐式装载的 ...
- Redis 源码走读(二)对象系统
Redis设计了多种数据结构,并以此为基础构建了多种对象,每种对象(除了新出的 stream 以外)都有超过一种的实现. redisObject 这个结构体反应了 Redis 对象的内存布局 type ...
- NAT+穿洞基础知识梳理
参考:https://www.cnblogs.com/shilxfly/p/6589255.html https://blog.csdn.net/phoenix06/article/details/7 ...