/* Use the slash-star style comments or the system won't see your
identification information */
/*
ID: lincans1
LANG: JAVA
TASK: combo
*/
import java.io.*;
import java.util.*;
public class combo {
private void count(int N, BufferedReader f, Set<String> set) throws IOException {
StringTokenizer st = new StringTokenizer(f.readLine());
int a1 = Integer.parseInt(st.nextToken());
int a2 = Integer.parseInt(st.nextToken());
int a3 = Integer.parseInt(st.nextToken());
for (int i = -2; i <= 2; i++) {
for (int j = -2; j <= 2; j++) {
for (int k = -2; k <= 2; k++) {
set.add("" +
((a1 + i + N) % N + 1) +
((a2 + j + N) % N + 1) +
((a3 + k + N) % N + 1)
);
}
}
}
}
public combo() throws IOException {
// Use BufferedReader rather than RandomAccessFile; it's much faster
BufferedReader f = new BufferedReader(new FileReader("combo.in"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("combo.out")));
int N = Integer.parseInt(f.readLine());
Set<String> set = new HashSet<>();
// count Farmer john's combination
count(N, f, set);
// count the master combination
count(N, f, set);
out.println(set.size());
out.close(); // close the output file
}
public static void main (String [] args) throws IOException {
new combo();
}
}
[Java] Combination Lock
猜你喜欢
转载自blog.csdn.net/weixin_41714373/article/details/112193818
今日推荐
周排行