• 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;
}

徐州网络赛C-Cacti Lottery【DFS】的更多相关文章

  1. 2018 ICPC 徐州网络赛

    2018 ICPC 徐州网络赛 A. Hard to prepare 题目描述:\(n\)个数围成一个环,每个数是\(0\)~\(2^k-1\),相邻两个数的同或值不为零,问方案数. solution ...

  2. ICPC 2019 徐州网络赛

    ICPC 2019 徐州网络赛 比赛时间:2019.9.7 比赛链接:The Preliminary Contest for ICPC Asia Xuzhou 2019 赛后的经验总结 // 比赛完才 ...

  3. 计蒜客 41391.query-二维偏序+树状数组(预处理出来满足情况的gcd) (The Preliminary Contest for ICPC Asia Xuzhou 2019 I.) 2019年徐州网络赛)

    query Given a permutation pp of length nn, you are asked to answer mm queries, each query can be rep ...

  4. [徐州网络赛]Longest subsequence

    [徐州网络赛]Longest subsequence 可以分成两个部分,前面相同,然后下一个字符比对应位置上的大. 枚举这个位置 用序列自动机进行s字符串的下标转移 注意最后一个字符 #include ...

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

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

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

    链接https://nanti.jisuanke.com/t/31455 思路 首先先枚举把剩下的数填入星号的情况(其实就是枚举星号的排列),这是对方所能知道的所有信息,然后对方将取八种决策中最优的情 ...

  7. 徐州网络赛B-BE,GE or NE【记忆化搜索】【博弈论】

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

  8. 徐州网络赛J-Maze Designer【最小生成树】【LCA】

    After the long vacation, the maze designer master has to do his job. A tour company gives him a map ...

  9. ACM-ICPC2018徐州网络赛 BE, GE or NE(对抗搜索+博弈+记忆化)

    BE, GE or NE 23.58% 1000ms 262144K   In a world where ordinary people cannot reach, a boy named &quo ...

随机推荐

  1. 第三百零五节,Django框架,Views(视图函数),也就是逻辑处理函数里的各种方法与属性

    Django框架,Views(视图函数),也就是逻辑处理函数里的各种方法与属性 Views(视图函数)逻辑处理,最终是围绕着两个对象实现的 http请求中产生两个核心对象: http请求:HttpRe ...

  2. Building a Non-blocking TCP server using OTP principles

    转自:https://erlangcentral.org/wiki/index.php/Building_a_Non-blocking_TCP_server_using_OTP_principles ...

  3. 关于C++中using namespace std

    原文链接:http://www.kuqin.com/language/20080107/3532.html <iostream>和<iostream.h>是不一样,前者没有后缀 ...

  4. c++ template<typename T>

    template <typename T> 网上查了半天不知所云,网上说的太多,俺只是要知道所需要的就可以了. 写了个程序试了一下,其实就是这个东西可以根据你所需要的类型就行匹配.其实就是 ...

  5. Loadrunner 9.5_webservice(SOAP)性能测试

    WebService定义:Webservice是一种新的使用基于XML标准和协议来交换信息的WEB应用程序.是基于SOAP(简单对象访问协议)消息的应该协议,只是为WEB页面或可执行程序提供编程接口. ...

  6. 【matlab】运动目标检测之"背景差分算法“

    clear; clc; i1=imread('D:\Work\1.png'); i2=imread('D:\Work\2.png'); i1=rgb2gray(i1); i2=rgb2gray(i2) ...

  7. Socket无连接简单实例

    使用无连接的套接字,我们能够在自我包含的数据包里发送消息,采用独立的读函数读取消息,读取的消息是使用独立的发送函数发送的.但是UDP数据包不能保证可靠传输,存在许多的因素,比如网络繁忙等等,都有可能阻 ...

  8. Strut2------获取界面返回的session,application,parameter

    1.Action类下的代码 public class ServletActionDemo extends ActionSupport { @Override public String execute ...

  9. 用cocos2d 2.1制作一个过河小游戏(4): 游戏主逻辑BaseLayer设计

    前段时间一直在忙.没有时间更新博客.今天还是抽点时间把最后一小部分游戏的实现放上来吧. BaseLayer.h: #import <GameKit/GameKit.h> #import & ...

  10. 5个基于Web的建模工具

    本文介绍 5 款很棒的直接可以在浏览器使用的建模工具,无需单独安装软件. 1. Creately提供在线图表和协助功能,包含多种建模语言(UML)支持,这里有一个简单的演示:here 2.Diagra ...