方法一 : 把 得分表 存到 二维数组中(只统计加分) 后面直接查表;
#include <iostream>
using namespace std;
const int N = 210;
int n, na, nb;
int a[N], b[N];
int res_a, res_b;
int cal[5][5] = {
0, 0, 1, 1, 0,
1, 0, 0, 1, 0,
0, 1, 0, 0, 1,
0, 0, 1, 0, 1,
1, 1, 0, 0, 0};
int main()
{
cin >> n >> na >> nb;
for(int i = 0; i < na; ++i) cin >> a[i];
for(int i = 0; i < nb; ++i) cin >> b[i];
int i = 0;
while (n --){
res_a = cal[a[i % na]][b[i % nb]];
res_b = cal[b[i % nb]][b[i % na]];
i ++;
}
cout << res_a << " " << res_b << endl;
return 0;
}
方法二: 直接写
#include <iostream>
using namespace std;
const int N = 200;
int n, a, b;
int a1[N],a2[N];
int A, B;
void check()
{
for(int i = 0; i < n; ++i)
{
if(a1[i % a] == 0 && a2[i % b] == 1) {B ++;continue;}
if(a1[i % a] == 0 && a2[i % b] == 2){A ++;continue;}
if(a1[i % a] == 0 && a2[i % b] == 3){A ++;continue;}
if(a1[i % a] == 0 && a2[i % b] == 4){B ++;continue;}
if(a1[i % a] == 1 && a2[i % b] == 0){A ++;continue;}
if(a1[i % a] == 1 && a2[i % b] == 2){B ++;continue;}
if(a1[i % a] == 1 && a2[i % b] == 3){A ++;continue;}
if(a1[i % a] == 1 && a2[i % b] == 4){B ++;continue;}
if(a1[i % a] == 2 && a2[i % b] == 0){B ++;continue;}
if(a1[i % a] == 2 && a2[i % b] == 1){A ++;continue;}
if(a1[i % a] == 2 && a2[i % b] == 3){B ++;continue;}
if(a1[i % a] == 2 && a2[i % b] == 4){A ++;continue;}
if(a1[i % a] == 3 && a2[i % b] == 0){B ++;continue;}
if(a1[i % a] == 3 && a2[i % b] == 1){B ++;continue;}
if(a1[i % a] == 3 && a2[i % b] == 2){A ++;continue;}
if(a1[i % a] == 3 && a2[i % b] == 4){A ++;continue;}
if(a1[i % a] == 4 && a2[i % b] == 0){A++;continue;}
if(a1[i % a] == 4 && a2[i % b] == 1){A++;continue;}
if(a1[i % a] == 4 && a2[i % b] == 2){B++;continue;}
if(a1[i % a] == 4 && a2[i % b] == 3){B++;continue;}
}
}
int main()
{
cin >> n >> a >> b;
for(int i = 0; i <a; ++i) cin >> a1[i];
for(int i = 0; i < b; ++i) cin >> a2[i];
check();
cout <<A << " " << B<< endl;
return 0;
}