2019-ICPC-南昌
Who is the Champion
题目描述
Soccer is probably the sport with the greatest fans in this country. However, the national team has a poor record on the world stage. In order to energize youth players, the Soccer National Championship is organized every year.
In this year, there are nn teams taking part in the championship. As usual, the single round-robin system is adopted so that each team plays every other team once. A standard match askes ten players and a goalkeeper for both teams, which contains 2222 players in total. They confront each other, defend their nets and attack the opponent’s goal in a rectangular grass court.
In a 90-minute game, they try to shoot again and again. When the game is over, the team with higher goals will win and obtain 33 points in the scoreboard, while the loser will obtain nothing. A very special but common case is that both teams get the same goals, which is a draw; then both of them will obtain one point in the scoreboard.
At the end of the season, the league will declare the champion which is the team with the highest score in total. If two or more teams have the same highest score in total, the one with the highest goal differential (which is calculated as the number of goals scored in all league matches minus the number of goals conceded) will be the champion. The worst situation that several teams have the same highest score in total and the same goal differential will be solved by extra play-offs.
Input
The first line contains an integer
(
1
⩽
n
⩽
100
)
(1⩽ n⩽100)
(1⩽n⩽100) indicating the number of teams.
Each of the following nn lines contains n n n integers.The j j j-th integer in the i i i-th line, which is non-negative and up to five, represents the number of goals scored by the i i i-th team against the j j j-th team.
We guarantee that a a a i i i, i i i = 0 =0 =0 for all 1 1 1 ≤ i ≤ n ≤i≤n ≤i≤n.
Output
If the league can declare the champion, output the index of the team who will be the champion or output play-offs (without quotes), if extra play-offs will be organized.
样例输入1
2
0 1
2 0
样例输出1
2
样例输入2
2
0 1
1 0
样例输出2
play-offs
样例输入3
3
0 1 3
1 0 4
0 0 0
样例输出3
2
题意:
给出一个N阶矩阵,
(
i
,
j
)
(i ,j )
(i,j) 处的数字表示这场比赛球队
i
i
i 踢进球队
j
j
j 多少球。两支球队平局则各加一分,一方获胜则获胜方加三分,负方不加分也不扣分。输出冠军队编号。优先比较分数,分数一样的话比较胜场数,胜场数一样的话输出
p
l
a
y
−
o
f
f
s
play-offs
play−offs。
思路:
定义一个结构体,三个变量队伍编号,得分,胜场数。
如果得分不同,按照分从高到低排序;如果分一样,按照胜场数从高到低排序。
胜了:得分加3,胜场数加一,同时输的那一方胜场数减一。
注意当
n
=
1
n=1
n=1 的时候特判一下。
代码:
#include <bits/stdc++.h>
using namespace std;
const int maxn=110;
struct node
{
int num;
int grade;
int cha;
}s[maxn];
bool cmp(node a,node b)
{
if(a.grade!=b.grade)
{
return a.grade>b.grade;
}
else
{
return a.cha>b.cha;
}
}
int main()
{
int n;
int a[maxn][maxn];
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
scanf("%d",&a[i][j]);
}
}
if(n==1)
printf("1\n");
else
{
for(int i=1;i<=n;i++)
{
s[i].num=i;
s[i].grade=0;
s[i].cha=0;
}
for(int i=1;i<n;i++)
{
for(int j=i+1;j<=n;j++)
{
if(a[i][j]>a[j][i])
{
s[i].grade+=3;
s[i].cha+=(a[i][j]-a[j][i]);
s[j].cha+=(a[j][i]-a[i][j]);
}
else if(a[i][j]==a[j][i])
{
s[i].grade+=1;
s[j].grade+=1;
}
else
{
s[j].grade+=3;
s[j].cha+=(a[j][i]-a[i][j]);
s[i].cha+=(a[i][j]-a[j][i]);
}
}
}
sort(s+1,s+n+1,cmp);
if(s[1].grade==s[2].grade&&s[1].cha==s[2].cha)
{
printf("play-offs\n");
}
else
{
printf("%d\n",s[1].num);
}
}
return 0;
}