原題下載
答案:
import java.io.*;
import java.util.*;
public class hps {
public static void main(String[] args) throws IOException {
// initialize file I/O
BufferedReader br = new BufferedReader(new FileReader("hps.in"));
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("hps.out")));
// read in the number of games
int n = Integer.parseInt(br.readLine());
// initialize a 2D array to store the number of each ordered pair that shows up
int[][] matches = new int[4][4];
for(int i = 0; i < n; i++) {
// read in one game
StringTokenizer st = new StringTokenizer(br.readLine());
int first = Integer.parseInt(st.nextToken());
int second = Integer.parseInt(st.nextToken());
matches[first][second]++;
}
// compute the maximum number of wins
int maximumWins = matches[1][2] + matches[2][3] + matches[3][1];
if(matches[1][3] + matches[3][2] + matches[2][1] > maximumWins) {
maximumWins = matches[1][3] + matches[3][2] + matches[2][1];
}
// print the answer
pw.println(maximumWins);
// close the file
pw.close();
}
}
以上就是關于【USACO 2017 January Contest, Bronze Problem 2. Hoof, Paper, Scissors】的解答,如需了解學校/賽事/課程動態,可至翰林教育官網獲取更多信息。
往期文章閱讀推薦:
2026 NOAI國際AI奧賽中國站即將開考!賽事地址&日程已出!
2027 USAAIO美國AI奧賽啟動報名!MIT/谷歌/Jane Street集體站臺!

? 2026. All Rights Reserved. 滬ICP備2023009024號-1