0%

北大 acm 3224 Go for Lab Cup! 解题报告

Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 5003 Accepted: 2637

Description

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?

Input

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 (i ≠ j) is 3 and the other one will be less than 3. All diagonal elements of the matrix are 0’s.

Output

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

Sample Input

40 0 3 23 0 3 12 2 0 23 3 3 0

Sample Output

4

题意:一个二维矩阵,aij 的值表示i赢了j几场比赛,比赛采取5局3胜制,所以只要赢了3局就不用再比,问赢得最多比赛的队员。其实就是问二维矩阵中哪一个有最多的3,如果有相等则取号码最小的

代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>

using namespace std;

int main()
{
int i,j,win[111]={0},n,t;

freopen("t.txt","rt",stdin);

while(cin>>n)
{

win[0]=0;

for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
cin>>t;
if(t>2)
win[i]++;
}

for(i=1;i<=n;i++)
if(win[i]>win[0])
{
t=i;
win[0]=win[i];
win[i]=0;
}

cout<<t<<endl;

}


return 0;
}
谢谢您的打赏,我的大英雄 ^_^
Thank you for your generosity, my big hero ^_^

更多内容请关注公众号「西小玛」