2018 徐州网络赛 C Cacti Lottery

题意:有3*3的矩阵,你知道其中的一些点的值,这些值你的对手也知道,并且你的对手还知道几个你不知道的值。你的对手做出最好的决策,让你来猜一猜你的对手获得的得分。

思路:很明显是搜索,先是枚举你的对手知道的情况,再根据每种情况进行搜索,做出最优的抉择。

坑点: CLION的优化做的也太好了吧,忘写了return 居然在本地能跑。。。

#include
using namespace std;
typedef long long LL;
typedef int lint;
lint reward[25];
void prework(){
    reward[6] = 10000;
    reward[7] = 36;
    reward[8]=720;
    reward[9] = 360;
    reward[10]=80;
    reward[11]=252;
    reward[12]=108;
    reward[13]=72;
    reward[14]=54;
    reward[15]=180;
    reward[16]=72;
    reward[17]=180;
    reward[18]=119;
    reward[19]=36;
    reward[20]=360;
    reward[21]=1080;
    reward[22]=144;
    reward[23]=1800;
    reward[24]=3600;
}
lint vis[10];
double ans;
lint solve_r1(  string& str  ){
    lint res = 0;
    lint c1 = str[0]+str[1]+str[2] - 3*'0';
    res  = max( res,reward[c1] );
    return res;
}
lint solve_r2(  string& str  ){
    lint res = 0;
    lint c2 = str[3]+str[4]+str[5] - 3*'0';
    res = max( res,reward[c2] );
    return res;
}
lint solve_r3(  string& str  ){
    lint res = 0;
    lint c3 = str[6]+str[7]+str[8] - 3*'0';
    res = max( res,reward[c3] );
    return res;
}
lint solve_c1(  string& str ){
    lint res = 0;
    lint c1 = str[0]+str[3]+str[6]-3*'0';
    res = max( res,reward[c1] );
    return res;
}
lint solve_c2(  string& str ){
    lint res = 0;
    lint c2 = str[1]+str[4]+str[7]-3*'0';
    res = max(res,reward[c2] );
    return res;
}
lint solve_c3(  string& str ){
    lint res = 0;
    lint c3 = str[2]+str[5]+str[8]-3*'0';
    res = max( res,reward[c3] );
    return res;
}
lint solve_d1(  string& str ){
    lint res = 0;
    lint c1 = str[0]+str[4]+str[8]-3*'0';
    res = max( res,reward[c1] );
    return res;
}
lint solve_d2(  string& str ) {
    lint res = 0;
    lint c2 = str[2] + str[4] + str[6] - 3 * '0';
    res = max(res, reward[c2]);
    return res;
}
double ansc1,ansc2 ,ansc3,ansr1,ansr2,ansr3,ansd1,ansd2,cnt3 = 0;
void dfs2(  string str,lint p ){
    if( p == 9 ){
        ansc1 += solve_c1( str ) ;ansc2 += solve_c2( str ) ;ansc3 += solve_c3( str ) ;
        ansr1 += solve_r1(str);ansr2 += solve_r2(str);ansr3 += solve_r3(str);
        ansd1 += solve_d1(str);ansd2 += solve_d2(str);
        cnt3++;
        return;
    }
    if( str[p] == '#' ){
        for( lint i = 1;i <= 9;i++ ){
            if( vis[i] ) continue;
            vis[i] = 1;
            str[p] = '0'+i;
            dfs2(str,p+1);
            vis[i] = 0;
        }
    }else{
        dfs2( str,p+1 );
    }
}
lint cnt4;
void dfs( string str,lint p ){
    if( p == 9 ){
        double ans2 = 0;
        cnt3 = 0;
        ansc1 = ansc2 = ansc3 = ansr1 = ansr2 = ansr3 = ansd1 = ansd2 = 0;
        dfs2( str,0 );
        ans2 = max( ans2,ansc1 );ans2 = max( ans2,ansc2 );ans2 = max( ans2,ansc3 );
        ans2 = max( ans2,ansr1 );ans2 = max( ans2,ansr2 );ans2 = max( ans2,ansr3 );
        ans2 = max( ans2,ansd1 ); ans2 = max( ans2,ansd2 );
        ans += ans2/cnt3;
        cnt4++;
        return;
    }
    if( str[p] == '*' ){
        for( lint i = 1;i <= 9;i++ ){
            if( vis[i] ) continue;
            vis[i] = 1;
            str[p] = '0'+i;
            dfs(str,p+1);
            vis[i] = 0;
        }
    }else{
        dfs( str,p+1 );
    }
}
int main(){
    prework();
    lint T;
    string str;
    scanf("%d",&T);
    while( T-- ){
        string str0;
        lint cnt = 0,cntdigit  = 0;
        for( lint i = 0;i < 3;i++ ){
            cin >> str;str0 += str;
        }
        cnt4 = 0;ans = 0;
        memset( vis,0,sizeof(vis));
        for( lint i = 0;i < str0.size();i++ ){
            if( isdigit( str0[i] ) ) {
                vis[str0[i]-'0'] = 1;
                cntdigit++;
            }
            if( str0[i] == '*' ) cnt++;
        }
        dfs(str0,0);
        printf("%.6f\n", (double)ans/cnt4 );
    }
    return 0;
}

 

你可能感兴趣的:(搜索,坑)