• 54.19%
  • 2000ms
  • 262144K

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:

Sum Reward
6 10000
7 36
8 720
9 360
10 80
11 252
12 108
13 72
14 54
15 180
16 72
17 180
18 119
19 36
20 360
21 1080
22 144
23 1800
24 3600

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

题目来源

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

感觉这道题的难度在于题意。读第一次的时候完全不知道在干什么。

* #有什么区别也搞不懂 样例的答案凑半天凑不出来

后来Leo来说的时候突然豁然开朗

比赛后来来不及敲了 其实也不太难

因为9的阶乘是很小的 所以可以枚举每一种可能

枚举所有*的可能 算每一种的期望

其中又要枚举每一种#的可能 要把每一种#的分数都加在一起找到最大的那个 作为当前*状态的分值除以#全排列数作为期望

把所有*的期望相加 除以A(cntjin+cntxing, cntxing) 就是答案


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<set>
//#include<bits/stdc++.h>
#define inf 0x7f7f7f7f7f7f7f7f
using namespace std;
typedef long long LL; int t;
bool vis[10];
int orinum[10], num[10], ans[10];
double marks[30] = {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};
vector<int> notused;
vector<int> xingpos;
vector<int> jinpos; double A(int n, int m)
{
double res = 1.0;
for(int i = 0; i < m; i++){
res *= (n - i);
}
return res;
} void maxexp()
{
ans[1] += marks[num[0] + num[1] + num[2]];
ans[2] += marks[num[3] + num[4] + num[5]];
ans[3] += marks[num[6] + num[7] + num[8]];
ans[4] += marks[num[0] + num[3] + num[6]];
ans[5] += marks[num[1] + num[4] + num[7]];
ans[6] += marks[num[2] + num[5] + num[8]];
ans[7] += marks[num[0] + num[4] + num[8]];
ans[8] += marks[num[2] + num[4] + num[6]];
} void dfsjin(int id)
{
//double res = 0;
if(id == jinpos.size()){
/*for(int i = 0; i < 9; i++){
cout<<num[i];
}
cout<<" "<<maxexp()<<endl;*/
maxexp();
}
else{
for(int i = 0; i < notused.size(); i++){
int j = notused[i];
if(vis[j]) continue;
num[jinpos[id]] = j;
vis[j] = true;
dfsjin(id + 1);
vis[j] = false;
}
}
//return res;
} double dfs(int id)
{
double res = 0;
if(id == xingpos.size()){
memset(ans, 0, sizeof(ans));
dfsjin(0);
int res = 0;
for(int i = 1; i <= 9; i++){
res = max(res, ans[i]);
}
return res / A(jinpos.size(), jinpos.size());
}
else{
for(int i = 0; i < notused.size(); i++){
int j = notused[i];
if(vis[j]) continue;
num[xingpos[id]] = j;
vis[j] = true;
res += dfs(id + 1);
vis[j] = false;
}
}
return res;
} int main()
{
cin>>t;
while(t--){
memset(vis, 0, sizeof(vis));
xingpos.clear();jinpos.clear();notused.clear();
int cntxing = 0, cntjin = 0;
for(int i = 0; i < 3; i++){
char s[5];
scanf("%s", s);
for(int j = 0; j < 3; j++){
orinum[i * 3 + j] = num[i * 3 + j] = s[j] - '0';
if(s[j] == '*'){
cntxing++;
xingpos.push_back(i * 3 + j);
}
else if(s[j] == '#'){
cntjin++;
jinpos.push_back(i * 3 + j);
}
else{
vis[num[i * 3 + j]] = true;
}
}
}
for(int i = 1; i <= 9; i++){
if(!vis[i]){
notused.push_back(i);
}
} double res = dfs(0) / A(cntjin + cntxing, cntxing);
printf("%.6f\n", res);
}
return 0;
}

最新文章

  1. Premiere使用整理
  2. [ActionScript 3.0] 对代码加密的有效方法
  3. scala泛函编程是怎样被选中的
  4. JAVA thread0.interrupt()方法
  5. Python: 常用list, string处理功能
  6. SQL数据库约束行为---防止数据完全重复
  7. Angular学习(8)- 路由
  8. 在使用Redis的客户端连接工具ServiceStack.Redis要注意的问题
  9. 基于WebForm+EasyUI的业务管理系统形成之旅 -- 施工计划安排(Ⅶ)
  10. centos 7 修改主机名称
  11. 0x1L
  12. BZOJ 2718: [Violet 4]毕业旅行( 最长反链 )
  13. itextSharp 使用模板(PdfTemplate)不规则分栏(ColumnText)
  14. Oracle数据库中in()参数超过一千报错代码报错
  15. Check the string CodeForces - 960A
  16. Oracle ctl模版
  17. ubuntu安装git
  18. 使用 scm-manager 搭建 git/svn 代码管理仓库(一)
  19. 动态改变UITabBarController的菜单文字
  20. 从TCP三次握手说起--浅析TCP协议中的疑难杂症(1)

热门文章

  1. linux -- Linux下的五个查找命令:grep、find、locate、whereis、which
  2. css -- css选择器
  3. myslq的索引类型为MyISAM和BDB的表:复合索引下的自增长
  4. Unity3D - 详解Quaternion类(一)
  5. spark on yarn(zookeeper 配置)
  6. 提取Unity游戏资源和脚本
  7. failed to push some refs to &#39;git@github.com:*/learngit.git&#39;
  8. supervisorctl unix:///var/run/supervisor.sock refused connection
  9. tiny6410移植opencv
  10. Java精选笔记_IO流【File(文件)类、遍历目录下的文件、删除文件及目录】