题目链接:https://www.luogu.org/problemnew/show/P1328
题意理解
这个就是拓展了石头剪刀布规则的游戏,本质上还是打表。
然后由于数据量的原因,可以直接暴力循环,而不需要求最小公倍数去计算。
代码
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static final int MAXN = 210;
static int[] A = new int[MAXN];
static int[] B = new int[MAXN];
static int Na, Nb, N;
private static int[][] scores = {
{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}
};
public static void main(String[] args) {
FastScanner fs = new FastScanner();
N = fs.nextInt();
Na = fs.nextInt();
Nb = fs.nextInt();
int sa = 0;
int sb = 0;
for(int i = 0; i < Na; i++) {
A[i] = fs.nextInt();
}
for(int i = 0; i < Nb; i++) {
B[i] = fs.nextInt();
}
for(int i = 0; i < N; i++) {
int t1 = A[i % Na];
int t2 = B[i % Nb];
sa += scores[t1][t2];
sb += scores[t2][t1];
}
System.out.println(sa + " " + sb);
}
public static class FastScanner {
private BufferedReader br;
private StringTokenizer st;
public void eat(String s) {
st = new StringTokenizer(s);
}
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
eat("");
}
public String nextLine() {
try {
return br.readLine();
} catch (Exception e) {
// TODO: handle exception
}
return null;
}
public boolean hasNext() {
while (!st.hasMoreElements()) {
String s = nextLine();
if (s == null) {
return false;
}
eat(s);
}
return true;
}
public String nextToken() {
hasNext();
return st.nextToken();
}
public int nextInt() {
return Integer.valueOf(nextToken());
}
}
}