2018 徐州网络赛 C

  •  262144K
 

Morgana is playing a game called cacti lottery. In this game, morgana has a 3 \times 33×3 grid graph, and the graph is filled with 11 ~ 99 , each number appears only once. The game is interesting, he doesn't know some numbers, but there are also some numbers he knows but don't want to tell you.

Now he should choose three grids, these three grids should be in the same column or in the same row or in the diagonal line. Only after this choice, can he know all numbers in the grid graph. Then he sums the three numbers in the grids he chooses, get the reward as follows:

SumReward
610000
736
8720
9360
1080
11252
12108
1372
1454
15180
1672
17180
18119
1936
20360
211080
22144
231800
243600

Then he wants you to predict the expected reward he will get if he is clever enough in the condition that he doesn't want to tell you something he knows.

("He is clever enough" means he will choose the max expected reward row or column or dianonal in the condition that he knows some numbers. And you know that he knows some number, but you don't know what they are exactly. So you should predict his expected reward in your opinion. )

Input

First line contains one integers TT (T \le 100T100) represents the number of test cases.

Then each cases contains three lines, giving the 3 \times 33×3 grid graph. '*' means Morgana knows but doesn't want to tell you, '#' means Morgana doesn't know, '0' ~ '9' means the public number that Morgana and you both know.

Output

TT lines, output the answer. If the answer is AA, and your answer is BB. Your answer will be considered as correct if and only if |(A-B)| < 1e-5(AB)<1e5 .

本题答案不唯一,符合要求的答案均正确

样例输入复制
2
123
***
###
12*
45#
78#
样例输出复制
10000
4313.16666667
题目来源

ACM-ICPC 2018 徐州赛区网络预赛

 

枚举 * 的情况,对于每种情况搜索 # 的情况,答案和的平均值即为期望。

代码如下:

 

#include <bits/stdc++.h>
using namespace std;
const int maxn=25;
typedef long long ll;
int score[25]={0,0,0,0,0,0,10000,36,720,360,80,252,108,72,54,180,72,180,119,36,360,1080,144,1800,3600};
int G[8][3]={
    {0,1,2},{3,4,5},{6,7,8},{0,3,6},{1,4,7},{2,5,8},{0,4,8},{2,4,6}
};
char mp[4][4];
int fac[maxn],p[maxn],g[maxn],pn=0,pg[maxn],pgg[maxn];
bool vis[maxn];
int cnt,q;
double res[maxn]; 
double ans;
void check(){
    for (int i=0; i<8; i++) res[i]=0;
    int a=0,b=0,c=0;
    for (int i=1; i<=9; i++){
        if(vis[i]) continue;
        pgg[c++]=i;
    }
    do{
        a=0,b=0;
        for (int i=0; i<pn; i++){
            if(p[i]>0) g[i]=p[i];
            else if(p[i]==0) g[i]=pg[a++];
            else g[i]=pgg[b++]; 
        }
        for (int d,i=0; i<8; i++){
            d=0;
            for (int j=0; j<3; j++) d+=g[G[i][j]];
            res[i]+=score[d];
        }
    }while(next_permutation(pgg,pgg+c));
    double d=0;
    for (int i=0; i<8; i++){
        res[i]=1.0*res[i]/fac[c];
        d=max(d,res[i]);
    }
    ans+=d;
}
void dfs(int pos){
    if(pos==cnt){
        q++;
        check();
        return;
    }
    for (int i=1; i<=9; i++){
        if(vis[i]) continue;
        vis[i]=1;
        pg[pos]=i;
        dfs(pos+1);
        vis[i]=false;
    }
}
int main(){
    // freopen("in.txt","r",stdin);
    fac[0]=1;
    for (int i=1; i<=9; i++) 
        fac[i]=fac[i-1]*i;
    int _;
    for (scanf("%d",&_); _; _--){
        cnt=q=0,ans=0;
        memset(vis,false,sizeof(vis));
        pn=0;
        for (int i=0; i<3; i++){
            scanf("%s",mp[i]);
            for (int j=0; j<3; j++){
                if(mp[i][j]=='*') cnt++,p[pn++]=0;
                else if(mp[i][j]=='#') p[pn++]=-1;
                else p[pn++]=mp[i][j]-'0',vis[mp[i][j]-'0']=1; 
            }
        }
        dfs(0);
        ans=1.0*ans/q;
        printf("%.7f\n",ans);
    }     
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/acerkoo/p/9638076.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值