題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=5873
Football Games
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1204 Accepted Submission(s): 466
At the first phase of the championships, teams are divided into M groups using the single round robin rule where one and only one game will be played between each pair of teams within each group. The winner of a game scores 2 points, the loser scores 0, when the game is tied both score 1 point. The schedule of these games are unknown, only the scores of each team in each group are available.
When those games finished, some insider revealed that there were some false scores in some groups. This has aroused great concern among the pubic, so the the Association of Credit Management (ACM) asks you to judge which groups' scores must be false.
For each case, the first line contains a positive integers M, which is the number of groups.
The i-th of the next M lines begins with a positive integer Bi representing the number of teams in the i-th group, followed by Bi nonnegative integers representing the score of each team in this group.
number of test cases <= 10
M<= 100
B[i]<= 20000
score of each team <= 20000
題目大意:
求給出的足球隊的分數是真是假
只需要滿足以下4個條件:
1. 總分數等於 n*(n-1),因爲每場比賽總能獲得兩分
2. 最高分數小於 2*(n-1)
3. 奇數分數必須是偶數個
4. 得0分的隊伍小於1個
我用的score[0]存的總分,但是我之前定義了一個maxn存總分 結果超時了
代碼:
#include<cstdio>
#include<iostream>
using namespace std;
int score[20020];
int main()
{
int t ;
while(scanf("%d", &t) != EOF)
{
while(t--)
{
int m,sum1,sum2,maxt=-1;
sum1 = 0;
sum2 = 0;
score[0]=0;
scanf("%d", &m);
for(int i = 1; i<= m; i++)
{
scanf("%d", &score[i]);
score[0] += score[i];
if(score[i]%2 != 0)
sum1++;
if(score[i] == 0)
sum2++;
if(score[i]>maxt)
maxt=score[i];
}
if(maxt > 2*(m-1))
{
printf("F\n");
continue;
}
if(score[0] != m*(m-1))
{
printf("F\n");
continue;
}
if(sum1%2!=0)
{
printf("F\n");
continue;
}
if(sum2>1)
{
printf("F\n");
continue;
}
printf("T\n");
}
}
return 0;
}