HDU 4287 Intelligent IME hash

Intelligent IME

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=4287

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

HINT

题意

用9宫格敲了N次,给m个字符串,问你每次敲击,能够敲出多少个单词

题解:

hash或者map搞一搞

代码

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
const int maxn=2501;
#define mod 1000000009
#define eps 1e-7
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
    while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
    return x*f;
}
//**************************************************************************************

//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
map<int,int> HH;
string s[5101];
map<string,int> H;
int ans[5101];
int main()
{
    int k=2;
    for(int i=0;i<=25;i++)
    {
        if(i==3||i==6||i==9||i==12||i==15||i==19||i==22)
            k++;
        HH[i]=k;
    }
    int t=read();
    while(t--)
    {
        H.clear();
        memset(ans,0,sizeof(ans));
        int n=read(),m=read();
        for(int i=0;i<n;i++)
            cin>>s[i];
        string s1;
        for(int i=0;i<m;i++)
        {
            cin>>s1;
            for(int j=0;j<s1.size();j++)
                s1[j]=char(HH[(s1[j]-‘a‘)]+‘0‘);
            H[s1]++;
        }
        for(int i=0;i<n;i++)
            printf("%d\n",H[s[i]]);
    }
}
时间: 2024-10-10 09:03:24

HDU 4287 Intelligent IME hash的相关文章

HDU 4287 Intelligent IME(map运用)

转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4287 Intelligent IME Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2091    Accepted Submission(s): 1031

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

Intelligent IME Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4776    Accepted Submission(s): 2227 Problem Description We all use cell phone today. And we must be familiar with the intelligen

HDU 4287 Intelligent IME (字典树 &amp;&amp; map)

分析:此题题意很简单,我就不说了,第一想到的就是用字典树做,首先你得考虑用哪个作为字典树,显然,这里用后面的字符串作为树更好. 接着就是套模板了.此题WA了无数次,找bug找了一天,也没找到头绪,后来看别人的结题报告,才明白,原来坑爹的把memset(mark)放在了循环外面,一直以为只循环一次就够了,,真是坑爹啊,,, 做到现在了,感觉字典树的问题基本上都能用map来解决. 代码一:字典树 学会了用内联,确实会快一些 #include <iostream> #include <cstr

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

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

hdu 4287 Intelligent IME

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 

杭电(hdu)ACM 4287 Intelligent IME

Intelligent IME Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3453    Accepted Submission(s): 1647 Problem Description We all use cell phone today. And we must be familiar with the intelligen

hdu 4278 Intelligent IME

Intelligent IME Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3487    Accepted Submission(s): 1659 Problem Description We all use cell phone today. And we must be familiar with the intelligen

HDU 4287 &lt;map&gt;的使用

对于这道题我主要要讲得是STL中map的简单使用. 先说说map的用处. map就是从键(key)到值(value)的映射.因为重载了[]运算符,map像数组的"高级版",例如可以用一个map<string,int>month_name来表示"月份名字到月份编号"的映射,然后用month_name["July"] = 7这样的方式来赋值. 它的意思就是map<string,int>month_name表示[ ] 里面代表的

hdu 4941 Magical Forest(hash映射)

题目链接:hdu 4941 Magical Forest 题目大意:给定N,M和K,表示在一个N*M的棋盘上有K个棋子,给出K个棋子的位置和值,然后是Q次操作,对应的是: 1 a b :交换a和b两行 2 a b : 交换a和b两列 3 a b :查询a b这个位置上棋子的值,没有棋子的话输出0 解题思路:一开始X[i]=i,X[j]=j,如果需要交换i和j,那么就令X[i]=j,X[j]=i即可,因为N和M很大,所以用map映射. #include <cstdio> #include <