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, 有 ...
随机推荐
- 区块链开发(五)git、truffle安装
truffle是以太坊最受欢迎的一个开发框架,本篇博客介绍truffle的下载安装过程. git安装 在安装truffle之前需要核实一下本机是否安装git程序.后面的程序安装需要依赖git. 输入以 ...
- 通过Eclipse生成可运行的jar包
本来转自http://www.cnblogs.com/lanxuezaipiao/p/3291641.html 我是个追新潮的人,早早用上了MyEclipse10.最近需要使用Fat jar来帮我对一 ...
- PHP无限极分类详谈
当你学习php无限极分类的时候,大家都觉得一个字“难”我也觉得很难,所以,现在都还在看,因为工作要用到,所以,就必须得研究研究. 到网上一搜php无限极分类,很多,但好多都是一个,并且,写的很乱,代码 ...
- WEB前端工程师整理的原生JavaScript经典百例
一.原生JavaScript实现字符串长度截取 二.原生JavaScript获取域名主机 三.原生JavaScript转义html标签 四.原生JavaScript时间日期格式替换 Date.prot ...
- 新电脑配置 git 同步github账户
1.下载安装git 2.初始化 仓库文件夹 git init 3.生成公钥ssh-keygen -t rsa -C "youremail@example.com"4.github ...
- C#调用耗时函数时显示进度条浅探
最近在做一个VSS日志分析工具,使用C#进行开发,在完成了所有功能后,发现,从服务器下载VSS日志非常耗时,因为此,导致工具使用体验不好,所以,准备增加一个进度条.鉴于C#不经常使用,一下子搞个进度条 ...
- GridView的TemplateField
BoundField只能显示一个单独的数据字段.如果我们想要在一个GridView列中显示两个或者更多的数据字段的值的时候该怎么办呢? 1. GridView的一列同时显示数据源中的两个字段 现需要显 ...
- 创建展开行明细编辑表单的 CRUD 应用
http://www.runoob.com/jeasyui/jeasyui-app-crud3.html jQuery EasyUI 应用 - 创建展开行明细编辑表单的 CRUD 应用 当切换数据网格 ...
- flutter 频道切换
https://github.com/flutter/flutter/wiki/Flutter-build-release-channels 频道说明页 https://flutter.dev/doc ...
- telnet执行过程及验证远程服务器是否打开
telnet执行过程: 工作原理: 当你用Telnet登录进入远程计算机系统时,你事实上启动了两个程序,一个 叫Telnet客户程序,它运行在你的本地机上:另一个叫Telnet服务器程序,它运 行在你 ...