「题解」Luogu 1328「生活大爆炸版剪刀石头布」

分析

这是一道模拟水题。

代码

#include<cstdio>
#include<vector>
int guess(int a,int b){
    if(a == 0){
        if(b ==0) return -1;
        else if(b == 1) return 0;
        else if(b == 2) return 1;
        else if(b == 3) return 1;
        else if(b == 4) return 0;
    }else if(a == 1){
        if(b == 0) return 1;
        else if(b == 1) return -1;
        else if(b == 2) return 0;
        else if(b == 3) return 1;
        else if(b == 4) return 0;
    }else if(a == 2){
        if(b == 0) return 0;
        else if(b == 1) return 1;
        else if(b == 2) return -1;
        else if(b == 3) return 0;
        else if(b == 4) return 1;
    }else if(a == 3){
        if(b == 0) return 0;
        else if(b == 1) return 0;
        else if(b == 2) return 1;
        else if(b == 3) return -1;
        else if(b == 4) return 1;
    }else if(a == 4){
        if(b == 0) return 1;
        else if(b == 1) return 1;
        else if(b == 2) return 0;
        else if(b == 3) return 0;
        else if(b == 4) return -1;
    }
}

int main(){
    int N,NA,NB,delta,ansA = 0,ansB = 0,j = 0,k = 0;scanf("%d %d %d",&N,&NA,&NB);
    std::vector<int> A,B;
    for(int i = 0;i < NA;i++) scanf("%d",&delta),A.push_back(delta);
    for(int i = 0;i < NB;i++) scanf("%d",&delta),B.push_back(delta);
    for(int i = 0;i < N;i++){
        if(guess(A[j],B[k]) == 1) ansA++;
        else if(guess(A[j],B[k]) == 0) ansB++;
        j++,k++;
        if(j >= NA) j = 0;
        if(k >= NB) k = 0;
    }

    printf("%d %d",ansA,ansB);

    return 0;
}