原题下载
答案:
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】的解答,如需了解学校/赛事/课程动态,可至翰林教育官网获取更多信息。
往期文章阅读推荐:
USACO计算机奥赛如何认证成绩?2026赛季黄金铂金组“定时开赛”规则详解!
USACO计算机奥赛考试语言是什么?C++、Python、Java选哪个效率最高?

© 2026. All Rights Reserved. 沪ICP备2023009024号-1