Problem Description
A mysterious country will hold a football world championships---Abnormal Cup, attracting football teams and fans from all around the world. This country is so mysterious that none of the information of the games will be open to the public till the end of all the matches. And finally only the score of each team will be announced.
At the first phase of the championships, teams are divided into MM 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.
Input
Multiple test cases, process till end of the input.
For each case, the first line contains a positive integers M, which is the number of groups.
The ii-th of the next MM lines begins with a positive integer Bi representing the number of teams in the ii-th group, followed by BiBi 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 <= 20000Output
For each test case, output M lines. Output ``F" (without quotes) if the scores in the i-th group must be false, output ``T" (without quotes) otherwise. See samples for detail.
Examples
Input
2
3 0 5 1
2 1 1Output
F
T
题意:t 组数据,每组给出 m 个队伍的积分情况,每个队伍之间两两进行比赛,赢的队伍获得 2 分,输的队伍不得分,平局的两个队伍各得 1 分,现在给出每支队伍的得分情况,问是否合法
思路:
给出的 m 个队伍可以构成一个竞赛图,问得分情况是否合法实质是在问竞赛图是否合法
根据竞赛图的兰道定理,将得分视为比分序列,将所有得分进行排序,然后依次处理:由于每次比赛胜利都会使得总分 +2,那么前 i 只队伍的得分情况必须大于等于 i*(i-1),当判断到最后一只队伍时,有前 n-1 只队伍的得分必须大于 n*(n-1)
Source Program
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
#define Pair pair<int,int>
const double EPS = 1E-10;
const int MOD = 1E9+7;
const int N = 100000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
int a[N];
int main(){
int t;
while(scanf("%d",&t)!=EOF){
while(t--){
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
sort(a+1,a+1+n);
int sum=0;
bool flag=true;
for(int i=1;i<=n;i++){
sum+=a[i];
if(i<=n-1){
if(sum<i*(i-1)){
flag=false;
break;
}
}
else{
if(sum!=i*(i-1)){
flag=false;
break;
}
}
}
if(flag)
printf("T\n");
else
printf("F\n");
}
}
return 0;
}