zoukankan      html  css  js  c++  java
  • Prediction and Restriction——UPC

    题目描述

    At an arcade, Takahashi is playing a game called 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)
    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≤105
    ·1≤K≤N−1
    ·1≤R,S,P≤104
    ·N,K,R,S, and P are all integers.
    ·|T|=N
    ·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.

    样例输入

    【样例15 2
    8 7 6
    rsrpr
    【样例27 1
    100 10 1
    ssssppr
    【样例330 5
    325 234 123
    rspsspspsrpspsppprpsprpssprpsr
    

    样例输出

    【样例127
    【样例2211
    【样例34996
    

    提示

    样例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.

    #pragma GCC optimize (2)
    #pragma G++ optimize (2)
    #include <bits/stdc++.h>
    #include <algorithm>
    #include <map>
    #include <queue>
    #include <set>
    #include <stack>
    #include <string>
    #include <vector>
    using namespace std;
    #define wuyt main
    typedef long long ll;
    #define HEAP(...) priority_queue<__VA_ARGS__ >
    #define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
    template<class T> inline T min(T &x,const T &y){return x>y?y:x;}
    template<class T> inline T max(T &x,const T &y){return x<y?y:x;}
    //#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
    //char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
    ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();
    if(c == '-')Nig = -1,c = getchar();
    while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();
    return Nig*x;}
    #define read read()
    const ll inf = 1e15;
    const int maxn = 2e5 + 7;
    const int mod = 1e9 + 7;
    #define start int wuyt()
    #define end return 0
    int n, r, s, p, k;
    int judge[1005];///ASCII从97--122其实开200就已经够了
    char pr[maxn], gr[maxn];
    start{
        /**
        ll n=read,m=read;
        char judge[10];
        ll cnt=0;
        while(m--){
            cin>>judge+1;
            if(judge[3]=='y'){
                if(cnt==0) printf("F
    ");
                else if(cnt!=0) printf("T
    ");
            }
            else if(judge[3]=='u') printf("%lld
    ",cnt);
            else if(judge[3]=='n'){
                ll shu=read;
                if(num[shu]==0) printf("F
    ");
                if(num[shu]==1) printf("T
    ");
            }
            else if(judge[3]=='l'){
                ll temp=read;
                if(num[temp]==0){
                    num[temp]=1;
                    cnt++;
                }
                else if(num[temp]==1){
                    num[temp]=0;
                    cnt--;
                }
            }
        }
        **/
        n=read,k=read,r=read,s=read,p=read;
        judge['r']=r;
        judge['s']=s;
        judge['p']=p;
        cin>>pr+1;
        for (int i=1;i<=n;i++) {
            if (pr[i]=='s') pr[i]=gr[i]='r';
            else if (pr[i]=='p') pr[i] = gr[i] = 's';
            else pr[i]=gr[i]='p';
        }
        for (int i=1; i<=n;i++)
            if(i+k<=n&&gr[i]==gr[i+k])
                gr[i+k]='9';///重复
        int ans=0;
        for(int i=1;i<=n;i++)
            if(pr[i]==gr[i])
                ans+=judge[gr[i]];
        printf("%d
    ", ans);
        end;
    }
     
    /**************************************************************
        Language: C++
        Result: 正确
        Time:11 ms
        Memory:2416 kb
    ****************************************************************/
    
  • 相关阅读:
    BZOJ 1013--[JSOI2008]球形空间产生器sphere(高斯消元)
    BZOJ 1012--[JSOI2008]最大数maxnumber(二分&单调栈)
    BZOJ 3357--[Usaco2004]等差数列(STL&DP)
    BZOJ 1011--[HNOI2008]遥远的行星(乱搞)
    BZOJ 1010--[HNOI2008]玩具装箱toy(斜率优化dp)
    BZOJ 5334--[Tjoi2018]数学计算(线段树)
    BZOJ 5395--[Ynoi2016]谁的梦(STL&容斥)
    BZOJ 1008--[HNOI2008]越狱(容斥&快速幂)
    一个典型的装饰器
    Nginx 配置文件详解
  • 原文地址:https://www.cnblogs.com/PushyTao/p/13144186.html
Copyright © 2011-2022 走看看