「2016 ACM/ICPC Asia Regional Dalian Online」F.Football Games

描述

传送门:我是传送门

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 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.

输入

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 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

输出

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.

样例

输入

2
3 0 5 1
2 1 1

输出

F
T

思路

  • 首先不难想到,n个队伍比赛,任意两支队伍之间有一场,那么就有$n(n-1)/22场,每场产生2分,所以一共产生n(n-1)$分。
  • 我们将所有的队伍按照比分的顺序进行排序,其实这样也是按照他们的胜场次数进行排序了(似乎并没有什么问题,如果写错了请指正
  • 每场比赛都有2分产生,计算前缀和sumsum一定等于i(i1)i∗(i−1),如果不相等的话,肯定也是存在问题的
  • 所以
    1. 排序
    2. 计算前缀和
  • 这样就可以得出最后的结果了

在动手写代码之前一定要好好考虑,拿不准就跟队友交流一下,这道题我错了9次,罚时爆炸(吐血

代码

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 1e5+10;
int a[MAXN];
ll sum = 0;
ll t,n,i;
int main()
{
    while(scanf("%d",&t)!= EOF)
    {
        for(int j = 1;j <= t;j++)
        {
            sum = 0;
            scanf("%d",&n);
            for(i = 1;i <= n;i++)
            {
                scanf("%d",&a[i]);
                sum += a[i];
            }
            if(sum != n*(n-1))
            {
                printf("F
");
            }
            else
            {
                sort(a+1,a+n+1);
                int fl = 0;
                sum = a[1];
                for(i = 2;i <= n;i++)
                {
                    sum += a[i];
                    if(sum < (i-1)*i)
                    {
                        fl = 1;
                        break;
                    }
                }
                if(fl)
                    printf("F
");
                else
                    printf("T
");
            }
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/duny31030/p/14305252.html