题目大意
小A和小B,要进行 \(N\) 次猜拳,每次按照一定周期出拳,胜负情况如下:
求出小A和小B分别赢了几次。
思路
枚举 \(N\) 次猜拳,每次比较 \(a[powera]\) 与 \(b[powerb]\) (poewra 与 powerb 是 a 和 b 数组的索引,详见代码)。
CODE
#include<bits/stdc++.h>
using namespace std;
int a[2005], b[2005];
int main(){
int n, na, nb, ansa = 0, ansb = 0;
cin >> n >> na >> nb;
for (int i = 1; i <= na; i++) {
cin >> a[i];
}
for (int i = 1; i <= nb; i++) {
cin >> b[i];
}
int powera = 1, powerb = 1;
for (int i = 1; i <= n; i++) {
if (powera > na) { //超过周期长度的特判
powera = 1;
}
if (powerb > nb) {
powerb = 1;
}
if (a[powera] == 0) {
if (b[powerb] == 1) {
ansb++;
}
if (b[powerb] == 2) {
ansa++;
}
if (b[powerb] == 3) {
ansa++;
}
if (b[powerb] == 4) {
ansb++;
}
}
if (a[powera] == 1) {
if (b[powerb] == 0) {
ansa++;
}
if (b[powerb] == 2) {
ansb++;
}
if (b[powerb] == 3) {
ansa++;
}
if (b[powerb] == 4) {
ansb++;
}
}
if (a[powera] == 2) {
if (b[powerb] == 0) {
ansb++;
}
if (b[powerb] == 1) {
ansa++;
}
if (b[powerb] == 3) {
ansb++;
}
if (b[powerb] == 4) {
ansa++;
}
}
if (a[powera] == 3) {
if (b[powerb] == 0) {
ansb++;
}
if (b[powerb] == 1) {
ansb++;
}
if (b[powerb] == 2) {
ansa++;
}
if (b[powerb] == 4) {
ansa++;
}
}
if (a[powera] == 4) {
if (b[powerb] == 0) {
ansa++;
}
if (b[powerb] == 1) {
ansa++;
}
if (b[powerb] == 2) {
ansb++;
}
if (b[powerb] == 3) {
ansb++;
}
}
powera++;
powerb++;
}
cout << ansa << " " << ansb << endl;
return 0;
}
标签:NOIP2014,洛谷,++,powerb,powera,int,ansa,ansb,P1328
From: https://www.cnblogs.com/yang-guang-hao-AKIOI/p/18391642