4/22/2018宁夏网络赛 H.Rock Paper Scissors Lizard Spock.

H.Rock Paper Scissors Lizard Spock.

Didi is a curious baby. One day, she finds a curious game, which named Rock Paper Scissors Lizard Spock.

The game is an upgraded version of the game named Rock, Paper, Scissors. Each player chooses an option . And then those players show their choices that was previously hidden at the same time. If the winner defeats the others, she gets a point.

The rules are as follows. 

Scissors cuts Paper

Paper covers Rock

Rock crushes Lizard

Lizard poisons Spock

Spock smashes Scissors

Scissors decapitates Lizard

Lizard eats Paper

Paper disproves Spock

Spock vaporizes Rock

(and as it always has) Rock crushes Scissors.

242dd42a2834349b5866a238c9ea15ce36d3be2f.jpg

(this pic is from baike.baidu.com)

But Didi is a little silly, she always loses the game. In order to keep her calm, her friend Tangtang writes down the order on a list and show it to her. Didi also writes down her order on another list, like p1.png.

(Rock-R Paper-P Scissors-S Lizard-L Spock-K)

However, Didi may skip some her friends' choices to find the position to get the most winning points of the game, like p2.png

Can you help Didi find the max points she can get?

Input:

The first line contains the list of choices of Didi's friend, the second line contains the list of choices of Didi.

(1<=len(s2)<=len(s1)<=1e6)

Output:

One line contains an integer indicating the maximum number of wining point.

忽略每行输出的末尾多余空格

样例输入1
RRRRRRRRRLLL
RRRS
样例输出1
3
样例输入2
RSSPKKLLRKPS
RSRS
样例输出2
一开始以为是自动机,后来没想明白状态这么多该怎么写,然后就写了暴力。。看见评论里有人说这数据也太水了吧,果断交了,就A了。。估计大家
都不敢写吧。。后来结束了,看见群里有人讨论这题,发现是fft,膜各位大佬。fft的方法codeforce528D,几乎原题,fft的方法,以后再补吧,
先暴力
#include <iostream>

using namespace std;

#define R 0
#define P 1
#define S 2
#define L 3
#define K 4

int grade[5][5];

void InitGrage(){
    for(int i=0;i<5;i++)
        for(int j=0;j<5;j++)
            grade[i][j]=-1;
    grade[S][P]=grade[P][R]=grade[R][L]=grade[L][K]=grade[K][S]=
        grade[S][L]=grade[L][P]=grade[P][K]=grade[K][R]=grade[R][S]=0;

    /*
    for(int i=0;i<5;i++){
        for(int j=0;j<5;j++){
            if(grade[i][j]==1){
                grade[j][i]=-1;
            }
        }
    }*/
}

int getByChar(char ch){
    switch (ch) {
    case 'R':return R;
    case 'S':return S;
    case 'K':return K;
    case 'L':return L;
    case 'P':return P;
    }
    return -1;
}
int A[1000005],B[1000005];
int main()
{
    int ch;
    int Alen=0,Blen=0;
    InitGrage();
    while((ch = getchar())!='\n'){
        A[Alen++]=getByChar(ch);
    }
    while((ch = getchar())!='\n' && ch != EOF){
        B[Blen++]=getByChar(ch);
    }

    int mxremain=-1;

    //for(int ebeg = Alen - Blen + 1,tbeg = ebeg - 1;tbeg>=0;tbeg--){
    for(int tbeg = Alen - Blen;tbeg>=0;tbeg--){
        int remain = Blen;
        for(int i=0;i<Blen && remain > mxremain;i++){
            remain += grade[B[i]][A[i+tbeg]];
        }
        if(remain>mxremain)
            mxremain=remain;
    }
    cout<<mxremain;

    return 0;
}

猜你喜欢

转载自blog.csdn.net/amous_x/article/details/80073699