Intelligent IME

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2479    Accepted Submission(s): 1212

Problem Description
  We all use cell phone today. And we must be familiar with the intelligent English input method on the cell phone. To be specific, the number buttons may correspond to some English letters respectively, as shown below:

  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?
 
Input
  First is an integer T, indicating the number of test cases. Then T block follows, each of which is formatted like this:

  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.
 
Output
  For each input block, output N integers, indicating how many words in the dictionary match the corresponding number sequence, each integer per line.
 
Sample Input
1
3 5
46
64448
74
go
in
night
might
gn
 
Sample Output
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(哈希)的更多相关文章

  1. HDU 4287 Intelligent IME(map运用)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4287 Intellig ...

  2. HDU 4287 Intelligent IME(字典树数组版)

    Intelligent IME Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. HDU 4287 Intelligent IME hash

    Intelligent IME Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...

  4. HDU 4287 Intelligent IME

    Intelligent IME Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. ACM学习历程—HDU 4287 Intelligent IME(字典树 || map)

    Description We all use cell phone today. And we must be familiar with the intelligent English input ...

  6. HDU 4287 Intelligent IME(string,map,stl,make_pair)

    题目 转载来的,有些stl和string的函数蛮好的: //numx[i]=string(sx); //把char[]类型转换成string类型 // mat.insert(make_pair(num ...

  7. HDU 4287 Intelligent IME(字典树)

    在我没用hash之前,一直TLE,字符串处理时间过长,用了hash之后一直CE,(请看下图)我自从经历我的字典树G++MLE,C++AC以后,一直天真的用C++,后来的CE就是因为这个,G++才支持这 ...

  8. 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 ...

  9. hdu Intelligent IME

    算法:字典树 题意:手机9键拼音:2:abc  3:def 4:ghi 5:jkl 6:mno 7:pqrs 8:tuv 9:wxyz: 第一行读入一个T,代表测试组数: 之后输入两个整数n和m, 有 ...

随机推荐

  1. Linux C程序异常退出怎么办——core文件帮你忙

    Linux C程序异常退出怎么办——core文件帮你忙 http://blog.csdn.net/zhu2695/article/details/51512138

  2. expect基础及实例

    expect基础及实例 http://blog.csdn.net/zhuying_linux/article/details/6900805

  3. Github上的几个C++开源项目

    Github上的几个C++开源项目 http://blog.csdn.net/fyifei0558/article/details/47001677 http://www.zhihu.com/ques ...

  4. Javascript制作放大镜

    方法一 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8 ...

  5. scrapy模拟知乎登录(无验证码机制)

    ---恢复内容开始--- spiders 文件夹下新建zhihu.py文件(从dos窗口中进入虚拟环境,再进入工程目录之后输入命令 scrapy genspider zhihu www.zhihu.c ...

  6. AutoIt 3.0 操作之初体验(第一个脚本hello world)

    AutoIt 目前最新是v3 版本,它是一个使用类似BASIC 脚本语言的免费软件,它被设计用来进行Windows GUI(图形用户界面)的自动化测试.它利用模拟键盘按键,鼠标移动和窗口/控件的组合来 ...

  7. 常用的LUA片段

    生成TS的办法 local t=ngx.now(); local n=os.date(,); n=n..-string.len(n)); ngx.say(n); 产生101至200的所有素数 func ...

  8. ITerms2在mac系统下的安装和配色,并和go2shell关联

    官网下载并安装 拖到应用文件夹使其在应用中展示 熟悉快捷键 无鼠标复制: cmd+f:查找首字母,再按tab向右选择词汇,按shift+tab向左选择词汇 分屏 cmd+d:垂直分屏 cmd+shif ...

  9. mvc路由问题

    概述 使用MVC Routing可以不必将URL映射到网站中特定文件.通过添加Routing规则,使URL能够安装指定的规则发送HTTP请求,这种方式能够简洁.方便.有效.快速的实现对指定页面的访问或 ...

  10. Undefined index: validate(thinkphp)

    今天在用thinkphp3.23时发现错误 NOTIC: [8] Undefined index: validate  此处是thinkphp核心目录\Think\Model.class.php 第 ...