虽然是模拟,但是我们可以用矩阵保存结果,来是其更加简便。
——代码
#include <cstdio>
#include <iostream> int map[][] = {{, , , , },
{, , , , },
{, , , , },
{, , , , },
{, , , , }};
int n, x, y, ans1, ans2;
int a[], b[]; inline int read()
{
int x = , f = ;
char ch = getchar();
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -;
for(; isdigit(ch); ch = getchar()) x = (x << ) + (x << ) + ch - '';
return x * f;
} int main()
{
int i, j;
n = read();
x = read();
y = read();
for(i = ; i < x; i++) a[i] = read();
for(i = ; i < y; i++) b[i] = read();
i = ;
j = ;
while(n--)
{
ans1 += map[a[i]][b[j]];
ans2 += map[b[j]][a[i]];
i = (++i) % x;
j = (++j) % y;
}
printf("%d %d\n", ans1, ans2);
return ;
}