*写下这篇博客的原因,不为别的,就因为这么一道签到题竟然困扰了五十五分钟,呜呜…谐音还挺像,哈哈哈 …嗝 *
题目:Prediction and Restriction
题目描述:
At an arcade, Takahashi is playing a game called R P S RPS RPS Battle, which is played as follows:
·The player plays N rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)
·Each time the player wins a round, depending on which hand he/she uses, he/she earns the following score (no points for a draw or a loss):
→R points for winning with Rock;
→S points for winning with Scissors;
→P points for winning with Paper.
·However, in the i-th round, the player cannot use the hand he/she used in the (i−K)-th round. (In the first K rounds, the player can use any hand.)
Before the start of the game, the machine decides the hand it will play in each round. With supernatural power, Takahashi managed to read all of those hands.
The information Takahashi obtained is given as a string T. If the i-th character of T ( 1 ≤ i ≤ N 1≤i≤N 1≤i≤N)
is r, the machine will play Rock in the i-th round. Similarly, p and s stand for Paper and Scissors, respectively.
What is the maximum total score earned in the game by adequately choosing the hand to play in each round?
Notes
In this problem, Rock Paper Scissors can be thought of as a two-player game, in which each player simultaneously forms Rock, Paper, or Scissors with a hand.
·If a player chooses Rock and the other chooses Scissors, the player choosing Rock wins;
·if a player chooses Scissors and the other chooses Paper, the player choosing Scissors wins;
·if a player chooses Paper and the other chooses Rock, the player choosing Paper wins;
·if both players play the same hand, it is a draw.
Constraints
· 2 ≤ N ≤ 1 0 5 2≤N≤10^5 2≤N≤105
· 1 ≤ K ≤ N − 1 1≤K≤N−1 1≤K≤N−1
· 1 ≤ R , S , P ≤ 1 0 4 1≤R,S,P≤10^4 1≤R,S,P≤104
· N , K , R , S , a n d P a r e a l l i n t e g e r s . N,K,R,S, and\ P\ are\ all\ integers. N,K,R,S,and P are all integers.
· ∣ T ∣ = N |T|=N ∣T∣=N
· T c o n s i s t s o f r , p , a n d s . T\ consists\ of\ r, p, and\ s. T consists of r,p,and s.
输入:
Input is given from Standard Input in the following format:
N K
R S P
T
输出:
Print the maximum total score earned in the game.
样例输入 Copy
【样例1】
5 2
8 7 6
rsrpr
【样例2】
7 1
100 10 1
ssssppr
【样例3】
30 5
325 234 123
rspsspspsrpspsppprpsprpssprpsr
样例输出 Copy
【样例1】
27
【样例2】
211
【样例3】
4996
提示
样例1解释
The machine will play {Rock, Scissors, Rock, Paper, Rock}.
We can, for example, play {Paper, Rock, Rock, Scissors, Paper} against it to earn 27 points. We cannot earn more points, so the answer is 27.
题目大意:题意很简单就是一个人面对着一个机器铁疙瘩 在那划拳,每赢一次得到相应的分数,这个人为了得到高分,一次都不想输,所以他开了个外挂,他可以知道每次机器所出得是什么(石头,剪刀 或 布);很明显,这样的话,他就可以每次都赢得胜利了。不过不要高兴的太早,开外挂也是需要付出一点代价的,要不然的话就更加的不公平了本来就已经很不公平了 ,这个代价就是给定你一个数字k,你第 i 次出的什么,不能和你在第 i 减 k 次出的相同;就是这样,好了,题目需要你求出这个人可以获得的最高分数
思路就在代码中,上代码
#include<bits/stdc++.h>
using namespace std;
char st[101011];
int main()
{
int n,k,r,s,p,i,ans=0,ss=0;
string t;
cin>>n>>k;
cin>>r>>s>>p;
cin>>t;
int len=t.size();
for(i=0;i<len;i++)
{
if(t[i]=='s'){
st[++ss]='r';
ans+=r;
}
else if(t[i]=='p'){
st[++ss]='s';
ans+=s;
}
else if(t[i]=='r'){
st[++ss]='p';
ans+=p;
}
}
//cout<<ans<<endl;
for(i=k;i<=ss;i++)
{
if(st[i]==st[i-k])
{
if(st[i]=='p'){
st[i]='_';
//这里为什么要把st[i]设为 '_'呢?那是因为,你在这次出什么只有两种可能
//但是为了得到高分,就要尽量避免这次出的的正好和下一次你能够获得胜利所出的相同
//原因很简单,就是相同的话,你又不能得到相应的分数了 ,所以要保证这次出的一定不影响 下一个k循环想要出什么
ans-=p;
}
if(st[i]=='s'){
st[i]='_';
ans-=s;
}
if(st[i]=='r'){
st[i]='_';
ans-=r;
}
}
}
cout<<ans<<endl;
return 0;
}