hdu5873 Football Games(模拟)

来源:互联网 发布:语音输入法软件下载 编辑:程序博客网 时间:2024/05/17 04:12

Football Games
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 101 Accepted Submission(s): 31

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, outputT” (without quotes) otherwise. See samples for detail.

Sample Input

2
3 0 5 1
2 1 1

Sample Output

F
T

题解:
这道题数据应当是不强的,我这个代码应该有数据过不了,最厉害的是Multiple test cases, process till end of the input,学习了!

#include<bits/stdc++.h>using namespace std;const int maxn=1e6+5;struct note {    int l,r;    long long grade;} Seg[maxn<<2];long long A[maxn];void Init(int i,int l,int r) {    Seg[i].l=l,Seg[i].r=r;    if(l==r) {        Seg[i].grade=A[l];        return;    }    int mid=(l+r)>>1;    Init(i<<1,l,mid);    Init(i<<1 |1,mid+1,r);    Seg[i].grade=Seg[i<<1].grade+Seg[i<<1 |1].grade;}long long Query(int i,int l,int r) {    if(Seg[i].l==l&&r==Seg[i].r) {        return Seg[i].grade;    }    int Mid=(Seg[i].l+Seg[i].r)>>1;    if(r<=Mid)        return Query(i<<1,l,r);    if(Mid<l)        return Query(i<<1 |1,l,r);    return Query(i<<1,l,Mid)+Query(i<<1 |1,Mid+1,r);}/*206 1 1 1 9 9 9*/int main() {    int T,n;    while(scanf("%d",&T)==1) {        while(T--) {            scanf("%d",&n);            long long Sum=0,now,gradeSum=0;            int One=0;            for(int i=1; i<=n; ++i) {                scanf("%lld",&A[i]);                Sum+=A[i];                if(A[i]==1) {                    ++One;                }            }            if(One>=3) {                printf("F\n");                continue;            }            if(n<=1) {                printf("F\n");                continue;            }            Init(1,1,n);            long long All=(long long)n*(n-1);            if(All!=Sum) {                printf("F\n");                continue;            }            int ans=1,Nums;            for(int i=1; i<n&&ans; ++i) {                now=Query(1,i,n);                if(All-gradeSum!=now) {                    ans=0;                    break;                }                if(A[i]==0) {                    for(int j=i+1; j<=n; ++j) {                        if(A[j]<=1) {                            ans=0;                            break;                        }                    }                }                if(!ans)break;                gradeSum+=A[i];            }            printf("%s\n",ans?"T":"F");        }    }    return 0;}
0 0
原创粉丝点击