(字典树应用) poj 1451 T9

[字典树] hdu 1298 poj 1451 T9 /** poj 1451 T9 在hdu 1298 上WA了, 原来问题出在单词的数目上,审题不慎,字符串长度开始定位10, 没注意到题目说单词数目不超过100。可是竟然不给我RE,返回结果很坑爹额。。。 */ #include #include #define N 50000 struct tireTree { int cnt; tireTre 阅读详情
T9
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 1809 Accepted: 692

Description

Background

A while ago it was quite cumbersome to create a message for the Short Message Service (SMS) on a mobile phone. This was because you only have nine keys and the alphabet has more than nine letters, so most characters could only be entered by pressing one key several times. For example, if you wanted to type "hello" you had to press key 4 twice, key 3 twice, key 5 three times, again key 5 three times, and finally key 6 three times. This procedure is very tedious and keeps many people from using the Short Message Service.

This led manufacturers of mobile phones to try and find an easier way to enter text on a mobile phone. The solution they developed is called T9 text input. The "9" in the name means that you can enter almost arbitrary words with just nine keys and without pressing them more than once per character. The idea of the solution is that you simply start typing the keys without repetition, and the software uses a built-in dictionary to look for the "most probable" word matching the input. For example, to enter "hello" you simply press keys 4, 3, 5, 5, and 6 once. Of course, this could also be the input for the word "gdjjm", but since this is no sensible English word, it can safely be ignored. By ruling out all other "improbable" solutions and only taking proper English words into account, this method can speed up writing of short messages considerably. Of course, if the word is not in the dictionary (like a name) then it has to be typed in manually using key repetition again.


Figure 8: The Number-keys of a mobile phone.

More precisely, with every character typed, the phone will show the most probable combination of characters it has found up to that point. Let us assume that the phone knows about the words "idea" and "hello", with "idea" occurring more often. Pressing the keys 4, 3, 5, 5, and 6, one after the other, the phone offers you "i", "id", then switches to "hel", "hell", and finally shows "hello".


Problem

Write an implementation of the T9 text input which offers the most probable character combination after every keystroke. The probability of a character combination is defined to be the sum of the probabilities of all words in the dictionary that begin with this character combination. For example, if the dictionary contains three words "hell", "hello", and "hellfire", the probability of the character combination "hell" is the sum of the probabilities of these words. If some combinations have the same probability, your program is to select the first one in alphabetic order. The user should also be able to type the beginning of words. For example, if the word "hello" is in the dictionary, the user can also enter the word "he" by pressing the keys 4 and 3 even if this word is not listed in the dictionary.

Input

The first line contains the number of scenarios.

Each scenario begins with a line containing the number w of distinct words in the dictionary (0<=w<=1000). These words are iven in the next w lines in ascending alphabetic order. Every line starts with the word which is a sequence of lowercase letters from the alphabet without whitespace, followed by a space and an integer p, 1<=p<=100, representing the probability of that word. No word will contain more than 100 letters.

Following the dictionary, there is a line containing a single integer m. Next follow m lines, each consisting of a sequence of at most 100 decimal digits 2�, followed by a single 1 meaning "next word".

Output

The output for each scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1.

For every number sequence s of the scenario, print one line for every keystroke stored in s, except for the 1 at the end. In this line, print the most probable word prefix defined by the probabilities in the dictionary and the T9 selection rules explained above. Whenever none of the words in the dictionary match the given number sequence, print "MANUALLY" instead of a prefix.

Terminate the output for every number sequence with a blank line, and print an additional blank line at the end of every scenario.

Sample Input

2
5
hell 3
hello 4
idea 8
next 8
super 3
2
435561
43321
7
another 5
contest 6
follow 3
give 13
integer 6
new 14
program 4
5
77647261
6391
4681
26684371
77771

Sample Output

Scenario #1:
i
id
hel
hell
hello

i
id
ide
idea


Scenario #2:
p
pr
pro
prog
progr
progra
program

n
ne
new

g
in
int

c
co
con
cont
anoth
anothe
another

p
pr
MANUALLY
MANUALLY
 
[字典树]poj 1451 T9 /** [字典树]poj 1451 T9 在hdu 1298 上WA了。 */ #include #include #define N 50000 struct tireTree { int cnt; tireTree *child[26]; }tt[N],*spt; void insert(char *s,int p,tireTree *& 阅读详情

相关推荐

从零构建锂电池主动均衡系统:Simulink仿真中的Buck-Boost拓扑实战指南

本文详细介绍了如何在Simulink中从零构建基于Buck-Boost拓扑的锂电池主动均衡系统。通过仿真环境搭建、参数优化、控制策略设计和性能评估,为工程师提供了完整的实战指南,帮助快速验证和优化均衡算法,提升电池组一致性与寿命。

gitlab7runner的博客 896

【POJ 1451 T9】字典树(Trie树)

POJ1451 本题题意比较有意思,大概就是模拟手机输入法,先给你一个用户的词库,即每个单词出现的次数,这个时候再按照九键输入法给你一个数字序列,问你在输入这个序列的过程中,出现的字符串顺序,也就是对于每个数字序列,给出一个最有可能出现的字符串。 这道题我的做法比较巧妙,但是不怎么会算复杂度,还是很快的过去了。首先我们考虑,对于每个数字序列,我们都可以用一个string去映射,这样我们可以用一...

lajiyuan的博客 636

淘特App x-sign参数逆向实战:从抓包到算法定位

本文详细解析了淘特App的x-sign参数逆向过程,从抓包分析到算法定位,涵盖了使用jadx-gui进行静态分析、Frida动态Hook验证以及Native层算法还原等关键技术。文章重点介绍了x-sign参数的生成机制及其在阿里系应用中的安全防护策略,为逆向工程师提供了实用的调试技巧和对抗策略。

5b6n7m8的博客 226

hdu 1298 T9(字典树+DFS)

题目连接:hdu 1298 T9 题目大意:模拟手机打字的猜想功能,根据概率,每按一个按键,输出可能性最高的串。先给定N个单词,以及频率, 然后是Q次询问,每次询问给定一个按按键的顺序,以1为终止。 解题思路:对单词表建立字典树,每个节点有一个经过的频率,这个频率是根据所有经过该节点的单词频率总和。然后 DFS搜索一遍,将答案保存在ans中。 #include #inc

不慌不忙、不急不躁 1504

大模型推理常见采样策略:Top-k, Top-p, Temperature, Beam Search

大模型推理采样策略,举例通俗易懂汇总介绍

qq_43243579的博客 2万+

告别枯燥的Unity编辑器脚本:Odin插件如何让游戏数据配置变得像搭积木一样简单?

本文详细介绍了Odin插件如何简化Unity编辑器脚本开发,使游戏数据配置变得直观高效。通过声明式特性和丰富的可视化工具,Odin让开发者告别繁琐的OnGUI代码,实现所见即所得的开发体验。文章重点展示了Odin的核心优势、魔法特性及实战案例,帮助Unity开发者提升工作效率。

weixin_28717411的博客 345

【poj 1451】T9 (字典树+深搜)

D - T9 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u SubmitStatusDescriptionBackground A while ago it was quite cumbersome to create a message for the Short Message Ser

ATOD 1077

ControlCAN.dll开发适配USBCAN_E/2E_U设备

摘要:本文提供了USBCAN_E/2E_U设备的配置指南:1)安装专用驱动;2)获取最新的ControlCAN.dll文件;3)修改VCI调用顺序,新增VCI_SetReference函数设置波特率;4)使用工具计算波特率配置值,并给出了常见波特率对应的代码参考值(如500K对应0x060007)。配置过程强调使用特定工具计算精确的波特率参数,并提供了相关软件下载链接。

weixin_43969033的博客 387

HDOJ1298(T9) 字典树 + dfs

T9Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 279Accepted Submission(s): 127 Problem Description A while ago it was quite cumbersome t...

weixin_30711917的博客 207

【DeepSeek+Office/WPS】智能办公新时代的全新利器

DeepSeek是一家专注于通用人工智能技术研发的中国科技公司,其核心产品DeepSeek-R1是一款开源的推理大模型,专注于复杂任务的高效处理,支持智能对话、文本生成、语义理解、计算推理、代码生成与补全等多种应用场景。作为国产、免费、开源且强大的AI平台,DeepSeek不仅致力于为终端用户提供高质量的智能服务,还为开发者提供了一整套完善的技术解决方案,帮助他们快速构建和部署自己的智能应用。

2303_77200324的博客 2790

Claude Code Cli 源码泄露事件全解析:从51万行代码中拆解AI Agent的记忆护城河

2026年3月,Anthropic的AI编程助手Claude Code意外泄露51万行核心代码,暴露了其多Agent架构、六级权限验证系统及创新的记忆机制。记忆系统采用四层设计:用户自定义框架、自动记忆提取、智能上下文压缩和纯文件存储。最独特的是"自动做梦"功能,AI会定期整理记忆,类似人类睡眠记忆巩固。代码还揭示未发布功能如电子宠物系统,但也暴露权限系统漏洞和代码质量问题。这次泄露展现了AI助手核心技术的复杂性,特别是其记忆系统如何通过透明可编辑的设计建立用户信任。

program哲学 468

POJ 1451 T9 [解题报告] Java

http://www.acmerblog.com/poj-1451-t9-blog-399.html 使用字典树和深度优先遍历

expleeve 679

CDD数据库文件制作(二)——服务配置(0x27)

主要根据诊断调查表,针对0x27服务在CDD中的每一步配置给出详细介绍 1.会话切换配置 1.1.根据诊断调查表进行信息提取 1.2.子功能添加 1.2.1.Level1安全等级1创建 1.2.2.Level3安全等级3创建 1.2.3.安全等级名字查看与修改 1.3.会话切换信息提取(应用程序下) 1.4.会话转换配置(应用程序下) 1.5.会话切换信息提取(引导程序下) 1.6.会话转换配置(引导程序下) 2.安全等级配置信息提取 2.1.安全访问配置(level1) 2.2.安全访问配置(level2

LOVE135149的博客 2929

POJ - 1451 T9 字典树

题目连接:点击查看 Background A while ago it was quite cumbersome to create a message for the Short Message Service (SMS) on a mobile phone. This was because you only have nine keys and the alphabet has more...

还我笑颜 319

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

POJ - 1451 T9 字典树好题

题意: 原来的按键手机都一般是九键,九键输入英文很麻烦,例如要键入“hello”,必须按两次键4、两次键3、三次键5、三次键5,最后按三次键6。 现有一种新的输入方案名叫“T9”,只需要不重复地按键,软件就会使用内置的字典来查找最可能的与输入匹配的单词。例如,输入“hello”,只要依次按下4,3,5,5,6各一次即可。当然,这也可能是“gdjjm”一词的输入,但是因为这不是一个合理的英语单词,所...

青春苦瓜 288

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

POJ 1451 T9 (字典树好题)

背景:为了方便九宫格手机用户发短信,希望在用户按键时,根据提供的字典(给出字符串和频数),给出各个阶段最有可能要打的单词。 题意: 首先给出的是字典,每个单词有一个出现频率。然后给出的是询问,每个询问有一个数字字符串,代表在手机上按了哪些键,以1结束。问按键的过程中最可能出现的单词分别是哪些。 思路:搞了很久.......一开始总想着以字母为各结点如何建树,询问......还是太年轻了。 以

Paradiser 1651

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

【POJ 1451】T9 中文题意&题解&代码(c++)

字典树

曾经追梦的happy时光 773

poj 1451 T9 【字典树 + DFS 模拟智能英语输入法】

T9 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3560   Accepted: 1280 Description Background  A while ago it was quite cumbersome to create a message f

世界很大 1245

(HDU)1298 (POJ)1451 - T9 【字典树】+【DFS】

模拟手机输入法的记忆功能,细节很多。

Doge 709

【POJ】1451 - T9(动态字典树 & dfs & STL)

点击打开题目 T9 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3806   Accepted: 1362 Description Background  A while ago it was quite cumbersome to cr

wyg1997 689

POJ 1451 字典树

这题的意思有点类似于一个输入法,就是按了一些键,蹦出单词库中频率最高的那个词汇 首先给出的是单词库,每个单词有一个出现频率。 然后给出的是一些询问,每个询问有一个字符串,代表在手机上按了哪些键,最后以1结束。问进行这些按键的过程中出现的单词分别是哪些。 思路就是字典树了。 以手机的8个键做8个指针来建立字典树。 每个结点存的除了指针外,还有出现频率最高的单词。 建树的时候需要注意,每个

水 1922

POJ1451 T9【Trie】

题目链接http://poj.org/problem?id=1451思路让你模拟手机输入法。 我这里是同步造了两棵字典树,一颗以字母为节点,统计probability,另一颗以键盘数字为节点,存当前按键路径probability最大的词和它的probability。 同步的方法是,用一个映射,将一个单词映射成数字,从而在两棵树之间同步插入。看了下网上的代码,好像不用第一棵树也能算出probabi

初涉_代码世界 467

poj 1451 T9 字典树

题目背景:为了方便手机用户发短信,希望在用户按键时,根据每个词出现的频数,给出每个阶段最有可能要打的词。 PS:相同的前缀频数要相加计算。 题目大意:有不同的几组测试样例,每个测试样例中有w个词及每个词出现的频数,然后是p组要打的词,按1键表示结束输入。要求输出按到每个键时最可能要打的词。 解题思路: 根据每个单词建立一棵“单词字典树”(A树), 附加域记录每个字母出现的频数。再根

暮雨潇湘 1763

『POJ 1451』T9

题目链接:http://poj.org/problem?id=1451 转载声明:http://blog.youkuaiyun.com/sg_siqing/article/details/12207153个人感想:感觉自己好弱鸡啊…从来没接触过这种变形了..为什么别人的脑洞就是那么大开.自己脑洞就特别的憋屈..看转载吧..不多说..我静静的去画个圈.真够蛋疼了…分析:字典树变形. 代码:/* Author:

Gavinjou大笨象的博客 353

短信智能输入 Trie POJ 1451 T9

http://poj.org/problem?id=1451 背景:为了方便九宫格手机用户发短信,希望在用户按键时,根据提供的字典(给出字符串和频数),给出各个阶段最有可能要打的单词。 题意: 首先给出的是字典,每个单词有一个出现频率。然后给出的是询问,每个询问有一个数字字符串,代表在手机上按了哪些键,以1结束。问按键的过程中最可能出现的单词分别是哪些。 注意:hell的权值为

ACM_10000h的专栏 692

POJ - 1451 T9

POJ - 1451 T9 Time Limit: 1000MS   Memory Limit: 10000KB   64bit IO Format: %I64d & %I64u Submit Status Description Background A while ago it was quite cumbers

WilliamCode的博客 951
上一篇: (二分+dp) poj 1631 Bridging signals
下一篇: (字典树+欧拉通路) poj 2513 Colored Sticks
Hashmat
博客等级 码龄16年 14粉丝 62原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值