C/C++:(100分)
本来想法是采用if判断的,但if判断太复杂太麻烦了,就改成打表了
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#define Max 500
int biao[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()
{
int N, a, b;
int Na[Max], Nb[Max];
int fen_a = 0; //记录a的得分
int fen_b = 0; //记录b的得分
scanf("%d %d %d", &N, &a, &b);
for (int i = 1; i <= a; i++)
{
scanf("%d", &Na[i]);
}
while (N > a)
{
for (int i = a + 1; i <= a * 2; i++)
{
Na[i] = Na[i - a];
}
a += a;
}
for (int i = 1; i <= b; i++)
{
scanf("%d", &Nb[i]);
}
while (N > b)
{
for (int i = b + 1; i <= b * 2; i++)
{
Nb[i] = Nb[i - b];
}
b += b;
}
for (int i = 1; i <= N; i++)
{
if (biao[Na[i]][Nb[i]] == 1)
{
fen_a++;
}
else if (biao[Na[i]][Nb[i]] == -1)
{
fen_b++;
}
}
printf("%d %d", fen_a, fen_b);
return 0;
}
python:(100分)
# 思路有部分区别于C/C++
# 原来C/C++的想法是延长数组以搞出完整的出拳规律
# 这里的话我打算搞两个指针来循环遍历数组
biao = \
[
[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]
] # 打表
a, b, c = map(int, input().split(" "))
bb = list(map(int, input().split(" ")))
cc = list(map(int, input().split(" ")))
fen_a = 0
fen_b = 0
b_index = -1 # 用于遍历 bb数组
c_index = -1 # 用于遍历 cc数组
for i in range(a):
b_index += 1
c_index += 1
if b_index >= b: # 判断,一旦越界就变成0,从头开始
b_index = b_index - b
if c_index >= c: # 判断,一旦越界就变成0,从头开始
c_index -= c
if biao[bb[b_index]][cc[c_index]] == 1:
fen_a += 1
elif biao[bb[b_index]][cc[c_index]] == -1:
fen_b += 1
print(f"{fen_a} {fen_b}")