Gym 101194L / UVALive 7908

题目链接:

http://codeforces.com/gym/101194/attachments

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5930

题意:

现有四支队伍两两打比赛,总共就是打六场比赛,每场比赛赢的队伍可得 $3$ 分,输的队伍得 $0$ 分,平局则两个队各得 $1$ 分。

现在给出四个队伍最终的积分,问能否确切给出每场比赛的结果。

题解:

显然,六场比赛,每场有三种结果,三进制数 $[0,3^6)$  暴力枚举所有可能的六场比赛结果即可。

AC代码:

#include<bits/stdc++.h>
using namespace std;
const int MAX=(int)pow(3,6);
const int t1[6]={1,1,1,2,2,3};
const int t2[6]={2,3,4,3,4,4};
int a,b,c,d;
int score[MAX][5];
inline bool Same(int s) {
    return score[s][1]==a&&score[s][2]==b&&score[s][3]==c&&score[s][4]==d;
}
void Solve()
{
    memset(score,0,sizeof(score));
    for(int sta=0;sta<MAX;sta++)
    {
        for(int i=0,s=sta;i<6;i++,s/=3)
        {
            int res=s%3;
            switch(res)
            {
            case 0:
                score[sta][t1[i]]+=3;
                break;
            case 1:
                score[sta][t2[i]]+=3;
                break;
            case 2:
                score[sta][t1[i]]++;
                score[sta][t2[i]]++;
                break;
            }
        }
    }
    int tot=0;
    for(int sta=0;sta<MAX;sta++) if(Same(sta)) tot++;
    if(!tot) printf("Wrong Scoreboard
");
    else if(tot==1) printf("Yes
");
    else printf("No
");
}
int main()
{
    int T;
    cin>>T;
    for(int kase=1;kase<=T;kase++)
    {
        cin>>a>>b>>c>>d;
        printf("Case #%d: ",kase);
        Solve();
    }
}
原文地址:https://www.cnblogs.com/dilthey/p/9906064.html