2013
11-12

# Go for Lab Cup!

The Lab Cup Table Tennis Competition is going to take place soon among laboratories in PKU. Students from the AI Lab are all extreme enthusiasts in table tennis and hold strong will to represent the lab in the competition. Limited by the quota, however, only one of them can be selected to play in the competition.

To make the selection fair, they agreed on a single round robin tournament, in which every pair of students played a match decided by best of 5 games. The one winning the most matches would become representative of the lab. Now Ava, head of the lab, has in hand a form containing the scores of all matches. Who should she decide on for the competition?

The input contains exactly one test case. The test case starts with a line containing n (2 ≤ n ≤ 100), the number of students in the lab. Then follows an n × n matrix A. Each element in the matrix will be one of 0, 1, 2 and 3. The element at row i and column j, aij, is the number of games won by the ith student in his/her match with the jth student. Exactly one of aij and aji (ij) is 3 and the other one will be less than 3. All diagonal elements of the matrix are 0’s.

Output the number of the student who won the most matches. In the case of a tie, choose the one numbered the smallest.

4
0 0 3 2
3 0 3 1
2 2 0 2
3 3 3 0

4

import java.util.*;

public class Main {

public static void main(String[] args) {
Scanner cin = new Scanner(System.in);

int num = Integer.valueOf(cin.nextLine()).intValue();
int[][] array = new int[num][num];

int max = 0;
int index = 0;

for(int i = 0; i < num; i++)
{
int rsum = 0;
for(int j = 0; j < num; j++)
{
array[i][j] = cin.nextInt();
if(array[i][j] == 3)
rsum++;
if(rsum > max)
{
max = rsum;
index = i;
}
}
}
System.out.println(index + 1);

}
}

1. Thanks for taking the time to examine this, I really feel strongly about it and love studying a lot more on this topic. If possible, as you acquire experience

2. if(j){
int ans=a ;
for(int x=j-1;x>=0;x–){
if(!a ) break;
ans=min(ans,a );
sum+=ans;
}
}
求解释，，dp的思路是什么呢？