博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 4287-Intelligent IME(哈希)
阅读量:6266 次
发布时间:2019-06-22

本文共 2378 字,大约阅读时间需要 7 分钟。

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 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define L long longusing 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]
pos(num,num+n); sort(num,num+n); for(int i=0;i

转载地址:http://mddpa.baihongyu.com/

你可能感兴趣的文章
lua(wax框架) 适配 64位操作系统
查看>>
css3和jquery实现的可折叠导航菜单(适合手机网页)
查看>>
POJ 1696 Space Ant(点积的应用)
查看>>
storyboard ID
查看>>
怎样用Google APIs和Google的应用系统进行集成(1)----Google APIs简介
查看>>
Leetcode: Number of Connected Components in an Undirected Graph
查看>>
Leetcode: Maximum Size Subarray Sum Equals k
查看>>
C#语言实现ArcGIS数据源重置之Set Data Source功能
查看>>
Codeforces Round #344 (Div. 2) A. Interview 水题
查看>>
Premiere Pro & After Effects插件开发调试方法
查看>>
墨西哥短暂生活杂谈
查看>>
第四篇:R语言数据可视化之折线图、堆积图、堆积面积图
查看>>
异步编程之Javascript Promises 规范介绍
查看>>
EnumRemarkAttribute,获取属性值
查看>>
GCC扩展(转--对看kernel代码有帮助
查看>>
MVC3中使用RadioButtonFor()
查看>>
单元测试的概念
查看>>
Android特效 五种Toast详解
查看>>
phpcms(4) V9 栏目管理
查看>>
php多进程pcntl学习(采集新浪微博)
查看>>