暴力模拟,循环数组。胜负条件看好。
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
const int maxn=1e4;
int read(){
int op=1,ans=0;char c;
c=getchar();
for(;(c<‘0‘||c>‘9‘)&&c!=‘-‘;c=getchar());
if(c==‘-‘) op=-1,c=getchar();
for(;c>=‘0‘&&c<=‘9‘;c=getchar()) ans*=10,ans+=c^48;
return ans*op;
}
int n,na,nb,awin=0,bwin=0;
int a[maxn],b[maxn];
int check(int a,int b){
if(a==0){
if(b==0) return 0;
else if(b==1) return -1;
else if(b==2) return 1;
else if(b==3) return 1;
else if(b==4) return -1;
}
else if(a==1){
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 -1;
}
else if(a==2){
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 1;
}
else if(a==3){
if(b==0) return -1;
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==4){
if(b==0) return 1;
else if(b==1) return 1;
else if(b==2) return -1;
else if(b==3) return -1;
else if(b==4) return 0;
}
}
int main(){
n=read(),na=read(),nb=read();
//printf("%d %d %d\n",n,na,nb);
for(int i=1;i<=na;i++) a[i]=read();
for(int i=1;i<=nb;i++) b[i]=read();
a[0]=a[na],b[0]=b[nb];
for(int i=1;i<=n;i++) a[i]=a[i%na];
for(int i=1;i<=n;i++) b[i]=b[i%nb];
for(int i=1;i<=n;i++){
int u=check(a[i],b[i]);
//printf("%d\n",u);
if(u==1) awin++;
else if(u==-1) bwin++;
}
printf("%d %d",awin,bwin);
return 0;
}
//0 scissors 1 rock 2 paper 3 xiyi 4 siboke
原文:https://www.cnblogs.com/liuziwen0224/p/2014d1t1.html