【洛谷普及组】【模拟】P1328 生活大爆炸版石头剪刀布

【题解】:

用心模拟即可,注意的是,写一个二维数组,但是对应的位置要弄成相反的,这样才行。

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N=2e4+10;
int x[5][5]={
        {0,  -1,  1,  1, -1},
        {1,   0, -1,  1, -1},
        {-1,  1,  0, -1,  1},
        {-1, -1,  1,  0,  1},
        {1,   1, -1, -1,  0}
};
int main()
{
    //cout<<"hello world"<<endl;
    int n,na,nb;
    scanf("%d%d%d",&n,&na,&nb);
    int a[N],b[N],A=0,B=0;
    for(int i=0;i<na;i++){ scanf("%d",&a[i]);}
    for(int i=0;i<nb;i++){ scanf("%d",&b[i]);}
    for(int i=0;i<n;i++){
        int t=x[a[i%na]][b[i%nb]];
        if(t==1){ A++; }
        else if(t==-1){ B++;}
    }
    printf("%d %d\n",A,B);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Z_sea/article/details/86762582
今日推荐