Description
n n 支球队参加比赛,每两支球队都会比一场,赢得一分输得零分,给出支球队最终得分,判断是否存在合法方案满足该得分情况
Input
第一行一整数 T T 表示用例组数,每组用例首先输入一整数表示球队数量,之后输入 n n 个整数表示这 n n 支球队的最终得分
Output
如果存在一个合法方案满足该得分情况则输出 The data have been tampered with! T h e d a t a h a v e b e e n t a m p e r e d w i t h ! ,否则输出 It seems to have no problem. I t s e e m s t o h a v e n o p r o b l e m .
Sample Input
2
3
2
1
0
3
2
2
2
Sample Output
It seems to have no problem.
The data have been tampered with!
Solution
Landau′s Theorem L a n d a u ′ s T h e o r e m :对于一个循环比赛计分问题,一个得分序列 s s 是合法的当且仅当:
1. 0≤si≤s2≤...≤sn 0 ≤ s i ≤ s 2 ≤ . . . ≤ s n
2. s1+s2+...+si≥C2i,i=1,2,...,n−1 s 1 + s 2 + . . . + s i ≥ C i 2 , i = 1 , 2 , . . . , n − 1
3. s1+s2+...+sn=C2n s 1 + s 2 + . . . + s n = C n 2
Code
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define maxn 55555
int T,n,a[maxn];
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
ll sum=0;
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
sort(a+1,a+n+1);
int flag=1;
for(int i=1;i<=n;i++)
{
sum+=a[i];
if(sum<1ll*i*(i-1)/2)flag=0;
if(i==n&&sum!=1ll*n*(n-1)/2)flag=0;
if(!flag)break;
}
printf("%s\n",flag?"It seems to have no problem.":"The data have been tampered with!");
}
return 0;
}