ACM-ICPC 2018 徐州赛区网络预赛 C Cacti Lottery(期望+暴力)
https://nanti.jisuanke.com/t/31455
题意
给一个3*3的方格填入 1-9 九个数
有些数是已知的,有些数是对方已知但我未知的,有些数是大家都未知的
我要计算取得最大的对应值的期望
分析
题意有点难懂。
首先先枚举把剩下的数填入星号的情况(其实就是枚举星号的排列),这是对方所能知道的所有信息,然后对方将取八种决策中最优的情况,而因为井号的存在,所以其排列也会影响每种决策的分数,所以接着要枚举井号的排列情况,对于每种情况累加每个决策的分数,最后枚举完后,要除以井号排列数(期望=分数*概率),然后对方便会选择期望最高的决策,累加到最后答案中,枚举完所有星号的之后,需要将最后答案除以星号排列数
#include<bits/stdc++.h>
using namespace std;
double ans;
int cnt,tot;
bool vis[];
char s[][];
int p[],a[],tmp[];
int state[];
int S[][]={
,,,
,,,
,,,
,,,
,,,
,,,
,,,
,,
};
int score[]={,,,,,,,,,,,,,,
,,,,,,,,,,};
int fac[];
void work(){
vector<int> num;
for(int i=;i<;i++) state[i]=;
for(int i=;i<=;i++){
if(!vis[i]){
num.push_back(i);
}
} do{
int na=,nb=;
for(int i=;i<;i++){
for(int j=;j<;j++){
if(s[i][j]=='*') tmp[i*+j]=p[na++];
else if(s[i][j]=='#') tmp[i*+j]=num[nb++];
else tmp[i*+j]=s[i][j]-'';
}
}
for(int i=;i<;i++){
int sum=;
for(int j=;j<;j++){
sum+=tmp[S[i][j]];
}
state[i]+=score[sum];
}
}while(next_permutation(num.begin(),num.end()));
double res=;
for(int i=;i<;i++){
res=max(res,state[i]*1.0/fac[num.size()]);
}
ans+=res;
}
void dfs(int pos){
if(pos==tot){
cnt++;
work();
return;
}
for(int i=;i<=;i++){
if(!vis[i]){
vis[i]=true;
p[pos]=i;
dfs(pos+);
vis[i]=false;
}
}
} int main(){
fac[]=;
for(int i=;i<;i++) fac[i]=fac[i-]*i;
int T;
scanf("%d",&T);
while(T--){
memset(vis,false,sizeof(vis));
tot=;
for(int i=;i<;i++){
scanf("%s",s[i]);
int len = strlen(s[i]);
for(int j=;j<len;j++)
if(s[i][j]=='*') tot++;
else if(isdigit(s[i][j])) vis[s[i][j]-'']=true;
}
ans=cnt=;
dfs();
ans=ans/cnt;
printf("%.8f\n",ans);
}
return ;
}
ACM-ICPC 2018 徐州赛区网络预赛 C Cacti Lottery(期望+暴力)的更多相关文章
- ACM-ICPC 2018 徐州赛区网络预赛 C Cacti Lottery(暴力+期望)
链接https://nanti.jisuanke.com/t/31455 思路 首先先枚举把剩下的数填入星号的情况(其实就是枚举星号的排列),这是对方所能知道的所有信息,然后对方将取八种决策中最优的情 ...
- 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 ...
随机推荐
- CORS——跨域请求那些事儿
在日常的项目开发时会不可避免的需要进行跨域操作,而在实际进行跨域请求时,经常会遇到类似 No 'Access-Control-Allow-Origin' header is present on th ...
- ZooKeeper的安装与部署
本文讲述如何安装和部署ZooKeeper. 一.系统要求 ZooKeeper可以运行在多种系统平台上面,表1展示了zk支持的系统平台,以及在该平台上是否支持开发环境或者生产环境. 表1:ZooKeep ...
- day 17-18 常用模块
time:时间 '''时间戳(timestamp):time.time()延迟线程的运行:time.sleep(secs)(指定时间戳下的)当前时区时间:time.localtime([secs])( ...
- IDEA+Maven+各个分支代码进行合并
各个模块的分支代码进行合并到一起:https://blog.csdn.net/xsj_blog/article/details/79198502
- 跳跳棋[LCA+二分查找]-洛谷1852
传送门 这真是一道神仙题 虽然我猜到了这是一道LCA的题 但是... 第一遍看题,我是怎么也没想到能和树形图扯上关系 并且用上LCA 但其实其实和上一道lightoj上的那道题很类似 只不过那时一道很 ...
- JS&Java实现常见算法面试题
Github上的算法repo地址:https://github.com/qcer/Algo-Practice (如果你觉得有帮助,可以给颗星星收藏之~~~) 一.Java实现部分 参见随笔分类的算法部 ...
- Binary Search(Java)(递归)
public static int rank(int[] array, int k, int front, int rear) { if(front > rear) return -1; int ...
- 桌面应用之electron开发与转换
桌面应用之electron开发与转换 一,介绍与需求 1.1,介绍 1. Electron简介 Electron是用HTML,CSS和JavaScript来构建跨平台桌面应用程序的一个开源库. Ele ...
- Django中的From和ModelForm
- Python进阶2---树的遍历和堆排序
二叉树的遍历 堆排序Heap Sort 堆排序的过程 完整过程: #打印完整的二叉树 import math #打印完全二叉树,此函数非必要只是为了显示便利! def print_tree(lst): ...