HDU 5873 Football Games(思维)

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

 

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

 

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

 

Sample Input
2 3 0 5 1 2 1 1
 

 

Sample Output
F T
 

 

Source
 

 

Recommend
wange2014   |   We have carefully selected several similar problems for you:  6730 6729 6728 6727 6726 
 
思路:这道题用的是巧妙的思路。假设从第一个人开始,到第b[i]个人,前面的人总是赢后面的人,那就有:每个人应得分数分别为 2 * (n - 1), 2 *(n - 2), 2 * (n - 3) .... 0。将实际值从大到小排序,如果(理论值) - (实际值)> 0,说明这个人有输了或者平了的记录;如果(理论值) - (实际值)= 0,说明莫得毛病;如果(理论值) - (实际值)< 0,说明这个情况时错误的。将所有的(理论值) - (实际值)相加,结果一定为0,若不为0,则为错误的情况。
#include<bits/stdc++.h>
using namespace std;
#define ll long long

const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const int maxn = 10000 + 8;

int m, b, num[20000 + 8], sum[20000 + 8];

int main()
{
    while(~scanf("%d", &m))
    {
        while(m--)
        {
            scanf("%d", &b);
            for(int j = 0; j < b; j++)
            {
                scanf("%d", &num[j]);
                sum[j] = 2 * j;
            }
            sort(num, num + b, greater<int>());
            sort(sum, sum + b, greater<int>());
            bool flag = 0;
            for(int j = 0; j < b; j++)
                sum[j] -= num[j];
            int s = 0;
            for(int j = 0; j < b; j++)
            {
                s += sum[j];
                if(s < 0)
                {
                    flag = 1;
                    break;
                }
            }
            if(s == 0 && !flag)
                printf("T\n");
            else
                printf("F\n");

        }
    }
    return 0;
}

 

posted @ 2019-09-25 21:17  明霞  阅读(200)  评论(0编辑  收藏  举报