POJ 2895 Best SMS to Type 发送短信的时间计算
来源:互联网 发布:php源代码怎么用 编辑:程序博客网 时间:2024/05/09 14:18
http://poj.org/problem?id=2895
Best SMS to Type
Time Limit: 1000MS Memory Limit: 65536K
Description
Using SMS today is more than a pleasing hobby. As the number of messages one sends through this service grows, the need to type them fast is better felt. Sometimes, one wonders how fast a message can be typed. Changing some words to their synonyms, might help type the whole message faster, if we were able to quickly calculate the time needed for a specific message.
In the following, we assume that each message is a string of capital English letters and space character. The letters 'A' through 'Z' are assigned to keys '2' to '9', as in the following figure. To type a letter, one should press its key 1, 2, 3, or 4 times, depending on the position of the letter from left to right.
If two consecutive letters of the message are mapped to one key, one should wait for the first letter to be fixed on the screen and then use the key again to type the second one. For instance, to type the letter 'X', one should press '9' twice. If the next letter of the message is not on the same key, one can continue to type the rest of the message. Otherwise, one has to wait for some time, so that the typed 'X' is fixed, and then the next letter ('W', 'X', 'Y', or 'Z') can be typed. To type whitespace, we use the key '1'.As there is no letter mapped to the key '1', the whitespace needs no time to be fixed.
You are given the time needed to press any key, and the time one should wait for a letter to be fixed. Your program should find the minimum time needed to type a nonempty string, given the above rules.
In the following, we assume that each message is a string of capital English letters and space character. The letters 'A' through 'Z' are assigned to keys '2' to '9', as in the following figure. To type a letter, one should press its key 1, 2, 3, or 4 times, depending on the position of the letter from left to right.
If two consecutive letters of the message are mapped to one key, one should wait for the first letter to be fixed on the screen and then use the key again to type the second one. For instance, to type the letter 'X', one should press '9' twice. If the next letter of the message is not on the same key, one can continue to type the rest of the message. Otherwise, one has to wait for some time, so that the typed 'X' is fixed, and then the next letter ('W', 'X', 'Y', or 'Z') can be typed. To type whitespace, we use the key '1'.As there is no letter mapped to the key '1', the whitespace needs no time to be fixed.
You are given the time needed to press any key, and the time one should wait for a letter to be fixed. Your program should find the minimum time needed to type a nonempty string, given the above rules.
Input
The input file contains multiple test cases. The first line of the input, contains t, the number of test cases that follow. Each of the following t blocks, describes a test case.
The first line of each block contains p and w (1 <= p,w <= 1000), which show the amount of time in milliseconds for pressing a letter and waiting for it to be fixed, respectively. The second line contains a non-empty string of length at most 1000, consisting of spaces or capital English letters. There is no leading or trailing spaces in a line.
The first line of each block contains p and w (1 <= p,w <= 1000), which show the amount of time in milliseconds for pressing a letter and waiting for it to be fixed, respectively. The second line contains a non-empty string of length at most 1000, consisting of spaces or capital English letters. There is no leading or trailing spaces in a line.
Output
For each test case, output one line showing the time needed to type the message in milliseconds.
Sample Input
12 10ABBAS SALAM
Sample Output
72
- POJ 2895 Best SMS to Type 发送短信的时间计算
- poj 2895 Best SMS to Type 模拟
- POJ 2895 Best SMS to Type 笔记
- POJ 2895 Best SMS to Type 再想想
- Best SMS to Type pku 2895
- BNUOJ Best SMS To Type
- 短信的发送(SMS)的发送
- Android发送短信SMS的编程
- SMS API发送短信
- blackberry 发送SMS短信
- 发送短信 SMS
- android 发送短信sms
- SMS短信发送
- Android 发送短信 sms
- SMS后台短信发送!
- android SMS 发送短信
- SMS短信发送应用
- SMS---发送短信
- 动态执行表不可访问,本会话的自动统计被禁止
- eCos 系统
- windows live write test
- 随便发发感想
- 学车过程中的一些胡思乱想
- POJ 2895 Best SMS to Type 发送短信的时间计算
- live writer 写csdn的blog
- Debug 版本 vs Release版本
- 内存访问越界(转)
- QTP(Quick Test Professional)
- vmware tools linux
- mini 2440 编写串口驱动常用名词
- datanode进程的分析(一)
- 硬盘分区表损坏修复实录