链接https://nanti.jisuanke.com/t/31455

思路

  • 首先先枚举把剩下的数填入星号的情况(其实就是枚举星号的排列),这是对方所能知道的所有信息,然后对方将取八种决策中最优的情况,而因为井号的存在,所以其排列也会影响每种决策的分数,所以接着要枚举井号的排列情况,对于每种情况累加每个决策的分数,最后枚举完后,要除以井号排列数(期望=分数*概率),然后对方便会选择期望最高的决策,累加到最后答案中,枚举完所有星号的之后,需要将最后答案除以星号排列数
#include<bits/stdc++.h>
#define pb push_back
#define M 20
using namespace std;
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},
};
int id[]={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 tp[M],g[M],p[M],vi[M],tot,i,F[M],Cnt;
double cnt[M],ans;
vector<int>pos;
char s[M]; void ck(){
vector<int>num;
for(int i=0;i<8;i++)cnt[i]=0;
for(int i=1;i<=9;i++){
if(!vi[i])num.pb(i);
}
do{
int a=0,b=0;
for(int i=0;i<9;i++){
if(g[i]>0)tp[i]=g[i];
else if(g[i]==0)tp[i]=p[a++];
else tp[i]=num[b++];
}
for(int i=0;i<8;i++){
a=0;
for(int j=0;j<3;j++){
a+=tp[G[i][j]];
}
cnt[i]+=id[a];
}
}while(next_permutation(num.begin(),num.end()));
double T=0;
for(int i=0;i<8;i++){cnt[i]=cnt[i]*1.0/F[num.size()];T=max(T,cnt[i]);}
ans+=T;
}
void dfs(int d){
if(d==pos.size()){
Cnt++;
ck();return;
}
for(int i=1;i<=9;i++){
if(!vi[i]){
vi[i]=1;p[d]=i;
dfs(d+1);vi[i]=0;
}
}
}
int main(){
int T;scanf("%d",&T);
F[0]=F[1]=1;for(i=2;i<=9;i++)F[i]=F[i-1]*i;
while(T--){
Cnt=tot=0;ans=0;
pos.clear();memset(vi,0,sizeof(vi));
for(int _=0;_<3;_++){
scanf("%s",s);for(i=0;i<strlen(s);i++){
if(s[i]=='#'){g[tot++]=-1;}
else if(s[i]=='*'){pos.pb(tot);g[tot++]=0;}
else {g[tot++]=s[i]-'0';vi[s[i]-'0']=1;}
}
}
dfs(0);
ans=ans*1.0/Cnt;
printf("%.7f\n",ans);
}
}

知识点

*暴力求期望:枚举所有情况的总分/所有情况数

ACM-ICPC 2018 徐州赛区网络预赛 C Cacti Lottery(暴力+期望)的更多相关文章

  1. ACM-ICPC 2018 徐州赛区网络预赛 C Cacti Lottery(期望+暴力)

    https://nanti.jisuanke.com/t/31455 题意 给一个3*3的方格填入 1-9 九个数 有些数是已知的,有些数是对方已知但我未知的,有些数是大家都未知的 我要计算取得最大的 ...

  2. ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心)

    ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心) Trace 问答问题反馈 只看题面 35.78% 1000ms 262144K There's a beach in t ...

  3. ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer (最大生成树+LCA求节点距离)

    ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer J. Maze Designer After the long vacation, the maze designer ...

  4. 计蒜客 1460.Ryuji doesn't want to study-树状数组 or 线段树 (ACM-ICPC 2018 徐州赛区网络预赛 H)

    H.Ryuji doesn't want to study 27.34% 1000ms 262144K   Ryuji is not a good student, and he doesn't wa ...

  5. ACM-ICPC 2018 徐州赛区网络预赛 B(dp || 博弈(未完成)

    传送门 题面: In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl n ...

  6. ACM-ICPC 2018 徐州赛区网络预赛 B. BE, GE or NE

    In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl named &qu ...

  7. ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study

    262144K   Ryuji is not a good student, and he doesn't want to study. But there are n books he should ...

  8. ACM-ICPC 2018 徐州赛区网络预赛 F. Features Track

    262144K   Morgana is learning computer vision, and he likes cats, too. One day he wants to find the ...

  9. ACM-ICPC 2018 徐州赛区网络预赛 I. Characters with Hash

    Mur loves hash algorithm, and he sometimes encrypt another one's name, and call him with that encryp ...

随机推荐

  1. Node使用 Express框架,实现文件上传

    一 安装依赖包 npm install multer --save 二 客户端上传文件 <!DOCTYPE html> <html> <head> <meta ...

  2. kraken-ejs创建一个项目【学习札记】

    Keep in Touch. 保持联络. Who’s calling? 是哪一位? You did right. 你做得对. You set me up! 你出卖我! kraken-express-e ...

  3. TZOJ 3481 Highway Construction(树的直径+最短路)

    描述 As head of the Accessible Commuting Movement (ACM), you've been lobbying the mayor to build a new ...

  4. [剑指Offer]判断一棵树为平衡二叉树(递归)

    题目链接 https://www.nowcoder.com/practice/8b3b95850edb4115918ecebdf1b4d222?tpId=0&tqId=0&rp=2&a ...

  5. bbs项目中的零碎点记录

    一.切换django的语言 在settings中修改django默认的语言 # LANGUAGE_CODE = 'en-us' # 切换django的语言,默认是英语的,我们把他修改为中文 LANGU ...

  6. twitter oa

    字符串括号匹配有效性: 要求从直接return改成了返回yes or no.需要添加到list后break,然后每次循环之前,boolean要重新初始化. array index报错是什么鬼?算了,脑 ...

  7. linux命令学习之:df

    df命令用于显示磁盘分区上的可使用的磁盘空间.默认显示单位为KB.可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息. 语法 df (选项) (参数) 选项 -a或--all:包含全部 ...

  8. Python爬虫项目--爬取自如网房源信息

    本次爬取自如网房源信息所用到的知识点: 1. requests get请求 2. lxml解析html 3. Xpath 4. MongoDB存储 正文 1.分析目标站点 1. url: http:/ ...

  9. Spring事务<tx:annotation-driven/>的理解

    在使用Spring的时候,配置文件中我们经常看到 annotation-driven 这样的注解,其含义就是支持注解,一般根据前缀 tx.mvc 等也能很直白的理解出来分别的作用. <tx:an ...

  10. python读写剪贴板

    #coding:utf-8 import os import time import win32api import win32con import win32clipboard as w impor ...