这道题我一开始竟然想复杂了,竟然手算都算不出题目给的测试用例!一看就知道我不是一个经常用手机发短信的人。这次热身我觉得题目都不是特别难,至少我遇到的ABC题基本上都低于平时做的pku题。B题本来我可以简化的,但是时间匆忙,懒得简化了。
我的程序代码:
/*
Problem B:Best SMS to Type
Time Limit:1000MS Memory Limit:65536K
Total Submit:446 Accepted:188
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.
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.
Output
For each test case, output one line showing the time needed to type the message in milliseconds.
Sample Input
1
2 10
ABBAS SALAM
Sample Output
72
*/
#include "iostream"
#include "string"
#include "stdio.h"
using namespace std;
void delays(int *delay)
{
int i;
for(i=0;i<8;i++)
if(delay[i])
delay[i]--;
}
int main()
{
int delay[8]={0},time=0;
int t,p,w,len,i=0,g,k;
char str[1000];
cin>>t;
while(t)
{
cin>>p>>w;
if(p<1||w>1000||p<=0||w<=0)
return 0;
str[0]=getchar();
gets(str);
//str[i]=getchar();
//while(1)
//{
// str[i]=getchar();
// if(str[i]=='/n')
// break;
// i++;
//}
//str[i]='/0';
len=strlen(str);;
for(i=0;i<len;)
{
g=str[i]-'A';
k=g;
g/=3;
if(g<5&&g>=0)
{
if(delay[g]!=0)
{
delays(delay);
time++;
continue;
}
time+=(((k%3)+1)*p);
k=w+1;
while(k)
{
delays(delay);
k--;
}
delay[g]+=w;
i++;
}
if(g>4)
{
g=str[i]-'P';
k=g;
g/=4;
if(g==0)
{
if(delay[5]!=0)
{
delays(delay);
time++;
continue;
}
time+=(((k%4)+1)*p);
k=w+1;
while(k)
{
delays(delay);
k--;
}
delay[5]+=w;
i++;
}
if(g!=0)
{
g=str[i]-'T';
k=g;
g/=3;
if(g==0)
{
if(delay[6]!=0)
{
delays(delay);
time++;
continue;
}
time+=(((k%3)+1)*p);
k=w+1;
while(k)
{
delays(delay);
k--;
}
delay[6]+=w;
i++;
}
if(g!=0)
{
g=str[i]-'W';
k=g;
g/=4;
if(g==0)
{
if(delay[7]!=0)
{
delays(delay);
time++;
continue;
}
time+=(((k%4)+1)*p);
k=w+1;
while(k)
{
delays(delay);
k--;
}
delay[7]+=w;
i++;
}
}
}
}
else if(g<0)
{
time+=p;
k=w+1;
while(k)
{
delays(delay);
k--;
}
i++;
}
}
cout<<time<<endl;
time=0;
t--;
}
return 0;
}