天天看點

poj 3224 Go for Lab Cup!

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

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

Sample Output

4      

這是一道較為簡單的水題~大緻的思想就是算出哪行三的個數最多~

開一個二維數組就行了~

由于要輸出序号~我用了個結構體~

輸出最大值的時候我用了qsort函數~隻是相練習一下這個函數的用法~其實沒這個必要~

下面是代碼~

#include"stdio.h"
#include"stdlib.h"
typedef struct in
 {
  int num;
  int count;
 };
struct in a[102];
int comp(const void *p1, const void *p2)     //qsort使用的指針
{
 struct in *px, *py;
 px=(struct in *)p1;
 py=(struct in *)p2;
 return px->count > py->count ? 1 : 0;
}
int main()
{
 int match[102][102];   //二維數組存成績
 int n;
 int i,j;
 freopen("01in.txt","r",stdin);
 freopen("01out.txt","w",stdout);
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  for(j=0;j<n;j++)
   scanf("%d",&match[i][j]);
  a[i].num=i+1;
 }
 for(i=0;i<n;i++)
 {
  a[i].count=0;
  for(j=0;j<n;j++)
  {
   if(match[i][j]>2)
    a[i].count++;
  } 
 }
 qsort(a,n,sizeof(struct in),comp);  //排序
  printf("%d",a[n-1].num);

}