码迷,mamicode.com
首页 > 其他好文 > 详细

Gym 101194L / UVALive 7908 - World Cup - [三进制状压暴力枚举][2016 EC-Final Problem L]

时间:2018-11-04 23:01:15      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:tac   hive   inline   ++   switch   href   div   cup   eof   

题目链接:

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\n");
    else if(tot==1) printf("Yes\n");
    else printf("No\n");
}
int main()
{
    int T;
    cin>>T;
    for(int kase=1;kase<=T;kase++)
    {
        cin>>a>>b>>c>>d;
        printf("Case #%d: ",kase);
        Solve();
    }
}

 

Gym 101194L / UVALive 7908 - World Cup - [三进制状压暴力枚举][2016 EC-Final Problem L]

标签:tac   hive   inline   ++   switch   href   div   cup   eof   

原文地址:https://www.cnblogs.com/dilthey/p/9906064.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!