ACM-ICPC 2018 徐州赛区网络预赛 C Cacti Lottery(暴力+期望)
链接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(暴力+期望)的更多相关文章
- ACM-ICPC 2018 徐州赛区网络预赛 C Cacti Lottery(期望+暴力)
https://nanti.jisuanke.com/t/31455 题意 给一个3*3的方格填入 1-9 九个数 有些数是已知的,有些数是对方已知但我未知的,有些数是大家都未知的 我要计算取得最大的 ...
- ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心)
ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心) Trace 问答问题反馈 只看题面 35.78% 1000ms 262144K There's a beach in t ...
- ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer (最大生成树+LCA求节点距离)
ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer J. Maze Designer After the long vacation, the maze designer ...
- 计蒜客 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 ...
- ACM-ICPC 2018 徐州赛区网络预赛 B(dp || 博弈(未完成)
传送门 题面: In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl n ...
- 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 ...
- 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 ...
- ACM-ICPC 2018 徐州赛区网络预赛 F. Features Track
262144K Morgana is learning computer vision, and he likes cats, too. One day he wants to find the ...
- 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 ...
随机推荐
- Win10 安装 Anaconda3 用 Anaconda3 安装TensorFlow 1.2 (只支持python3.5)
Win10 安装 Anaconda3 1.安装Anaconda3 选择相应的Anaconda进行安装,下载地址点击这里,下载对应系统版本的Anaconda,官网现在的版本是Anaconda 4.3.1 ...
- HDU 4940 Destroy Transportation system(无源汇上下界网络流)
Problem Description Tom is a commander, his task is destroying his enemy’s transportation system. Le ...
- php解析优酷网上的视频资源去广告
1.过程原理解析: 一.准备工作 所谓工欲善其事必先利其器,做好破解的准备工作会令你事半功倍. 1.首先准备一个Http抓包工具,PC上推荐Fiddler或者Postman,iOS上推荐Surge 2 ...
- Bootstrap(7) 输入框和导航组件
一.输入框组件 文本输入框就是可以在<input>元素前后加上文字或按钮,可以实现对表单控件的扩展. //在左侧添加文字 <!-- //在左侧添加文字 --> ...
- 工作中用Git对项目进行管理
前言 之前一直是用svn来管理代码的,今天第一次用git来管理代码,从安装.上传代码过程中遇到了很多问题,Github中建的repository之前还是https协议,最后不知道怎么又变成了git协议 ...
- 线特征---LSD算法(二)
上一节介绍了一些资源和实验结果,这节主要是介绍LSD算法理论. 直线段检测算法---LSD:a Line Segment Detector LSD的核心是像素合并于误差控制.利用合并像素来检测直线段并 ...
- js 正则表达式:密码必须由6-12位数字加字母组成
^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,12}$
- netcore sqlserver linq contains生成的sql语句不是使用like而是charIndex
在ef中使用linq调用了contains,结果怎么都查不到值,打开sqlserver profiler 发现生成的sql语句不是使用like...而是CharIndex 参考文档:https://s ...
- springBoot整合Quarzt2.3
首先,你要配置好springboot的配置(在resources下) 我把其改为application.yml # Tomcat server: tomcat: uri-encoding: UTF-8 ...
- C# oracle 日期型字段,使用参数传值时,遇到ORA-01810: format code appears twice错误
C#操作oracle数据库时,发现使用to_date('2014-01-03 18:00:00','yyyy-mm-dd hh:MM:ss')时,会出现ORA-01810: format code a ...