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

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 100T≤100) 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∣(A−B)∣<1e−5 .

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

样例输入复制

2
123
***
###
12*
45#
78#

样例输出复制

10000
4313.16666667
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define inf 0x3f3f3f
using namespace std;
#define mod 1000000007
const int maxn=1000115;
map<int,pair<int,int> >m1,m2;
int m3[100];
int g[11][11];
int vis[11],sum[10];
int cnt1,cnt2,k=0;
double ans;
void init(){
m3[6]=10000;
m3[7]=  36;
m3[8]=	720;
m3[9]=	360;
m3[10]=	80;
m3[11]=	252;
m3[12]=	108;
m3[13]=	72;
m3[14]=	54;
m3[15]=	180;
m3[16]=	72;
m3[17]=	180;
m3[18]=	119;
m3[19]=	36;
m3[20]=	360;
m3[21]=	1080;
m3[22]=	144;
m3[23]=	1800;
m3[24]=	3600;
}
double A(int n,int m){
    double res=1.0;
    for(int i=1;i<=m;i++)
        res*=(n-i+1);
    return res;
}
void dfs1(int x){
    if(x>cnt2){
        int l=0;
        for(int i=0;i<3;i++){
           sum[l++]+=m3[(g[i][0]+g[i][1]+g[i][2])];
        }
        for(int j=0;j<3;j++){
          sum[l++]+=m3[(g[0][j]+g[1][j]+g[2][j])];
        }
        sum[l++]+=m3[(g[0][0]+g[1][1]+g[2][2])];
        sum[l++]+=m3[(g[0][2]+g[1][1]+g[2][0])];

        return ;
    }
    for(int i=1;i<=9;i++){
        if(vis[i]==1)continue;
        vis[i]=1;
        g[m2[x].first][m2[x].second]=i;
        dfs1(x+1);
        vis[i]=0;
    }
}
void dfs(int x){

    if(x>cnt1){
         mem(sum,0);
        dfs1(1);
        int maxn=0;
        for(int i=0;i<8;i++){
         maxn=max(maxn,sum[i]);
        }ans+=(double)maxn/A(cnt2,cnt2);
        return ;
    }
    for(int i=1;i<=9;i++){
        if(vis[i]==1)continue;
        vis[i]=1;
        g[m1[x].first][m1[x].second]=i;
        dfs(x+1);
        vis[i]=0;
    }
}
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
            mem(vis,0);
            mem(g,0);
            init();
        char s[20];
        cnt1=cnt2=0;
        ans=0;
     for(int i=0;i<3;i++){
        scanf("%s",s);
        for(int j=0;j<strlen(s);j++){
            if(s[j]>='0'&&s[j]<='9'){vis[s[j]-'0']=1;g[i][j]=s[j]-'0';}
            if(s[j]=='*'){ m1[++cnt1]=make_pair(i,j);g[i][j]=-1;}
            if(s[j]=='#'){m2[++cnt2]=make_pair(i,j);g[i][j]=-1;}
            }
        }
        //cout<<cnt1<<" "<<cnt2<<endl;
        dfs(1);
        //cout<<ans<<endl;
        ans/=A(cnt1+cnt2,cnt1);
        printf("%.8lf\n",ans);
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值