toj 4612 A Shooting Game

时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte
总提交: 4 测试通过:4

描述

A and B are playing a shooting game on a battlefield consisting of square-shaped unit blocks. The blocks are occupying some consecutive columns, and the perimeter of the figure equals the perimeter of its minimal bounding box. The figure (a) below is a valid battlefield, but (b) and (c) are not, because in (b), there is an empty column; in (c), the perimeter of figure is 14, but the perimeter of the bounding box (drawn with dashed lines) is 12. With the help of gravity, each block is either located on another block, or sitting on the ground. To make the battlefield look more exciting, it must not be a perfect rectangle (i.e. it is not allowed that every column has the same height)

Here is the rule of the game:

A and B shoot by turn. A starts first.

Before shooting, the player first select one row with at least one block, and one of the two directions “left” and “right”, then shoot at this row along that direction. The power of the shoot is one of 1, 2 or 3, each with probability of 1/3. The power of shoot is the number of blocks (not necessarily consecutive) that can be destroyed in this shoot. If the total number of blocks on this row is less than the power of shoot, then all the blocks on this row is destroyed. For example, if the player chooses to shoot the 3rd row from the bottom, with direction “right”, power 2, and there are 4 blocks on this row, then the left-most two blocks are destroyed.

After each shoot, blocks in the air fall down vertically. The next player cannot shoot before all the blocks stop falling.

Realize that the intermediate battlefields do not have to follow the constraints for starting battlefields. For example, it could happens some situations looking as figures (b) or (c), and then, if the power is p, the leftmost/rightmost p blocks of columns which contain a block in this row are destroyed (skipping empty positions).

He who destroys the last block wins.

Assume the starting battlefield is . According to rule 1, A shoots first. The table below shows three (not all) possible outcomes of the first shot:

Assume Alice and Bob are both very clever (always follows the strategy that maximizes the probability he/she wins), what is the probability that Alice wins?

输入

There will be at most 25 test cases, each with two lines. The first line is a single integer n ( 1n6), the number of columns. The second line contains nintegers h1, h2, …, hn ( 1hi6), the heights of the columns from left to right. The battlefield is guaranteed to satisfy the restrictions in the problem (perimeter of figure equals that of the minimal bounding box, and is not a perfect rectangle). Input is terminated by n = 0.

输出

For each test case, print a single line, the probability that A wins, to six decimal points.

样例输入

3
2 1 1

样例输出

0.555556

/*
本题采用记忆化搜索*/#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;
#define FOR(i, s, t) for(int i = s; i <= t; ++i)const int MAXS = 50010;
const int MAXN = 8;
const double EPS = 1e-8;double a[7][7][7][7][7][7];double solve(int p1, int p2, int p3, int p4, int p5, int p6) {//solve函数求当前状态下获胜的概率的最大值if(a[p1][p2][p3][p4][p5][p6] > EPS) return a[p1][p2][p3][p4][p5][p6];//若当前位置已经存储了此状态下的最优解,则直接使用if(p1 + p2 + p3 + p4 + p5 + p6 == 0) return 0;//所有的列都为0,表示所有的木块全部打完int v1, v2, v3, v4, v5, v6;double ret = 0;//记录最优解for(int i = 1; i <= 6; ++i) {//从左边打的情况double tmp = 0;//i从1到6各个情况下的解for(int j = 1; j <= 3; ++j) {//射击威力的随机值v1 = p1, v2 = p2, v3 = p3, v4 = p4, v5 = p5, v6 = p6;//将原始数据另存,保证每次都从此状态出发搜索,每一行木块的个数int k = j;//记录当前的威力if(v1 >= i && k) --v1, --k;//if(v2 >= i && k) --v2, --k;if(v3 >= i && k) --v3, --k;if(v4 >= i && k) --v4, --k;if(v5 >= i && k) --v5, --k;if(v6 >= i && k) --v6, --k;if(k == j) continue;//没打中,此轮轮空tmp += 1./3 * (1 - solve(v1, v2, v3, v4, v5, v6));//每次循环的结果都是1/3,乘以另一个人射击赢的概率,所以用反面考虑}if(tmp > ret) ret = tmp;//如果概率大于记录值则更新记录值tmp = 0;for(int j = 1; j <= 3; ++j) {//左边情况同上v1 = p1, v2 = p2, v3 = p3, v4 = p4, v5 = p5, v6 = p6;int k = j;if(v6 >= i && k) --v6, --k;if(v5 >= i && k) --v5, --k;if(v4 >= i && k) --v4, --k;if(v3 >= i && k) --v3, --k;if(v2 >= i && k) --v2, --k;if(v1 >= i && k) --v1, --k;if(k == j) continue;tmp += 1./3 * (1 - solve(v1, v2, v3, v4, v5, v6));}if(tmp > ret) ret = tmp;}return a[p1][p2][p3][p4][p5][p6] = ret;//记录当前步最优解
}int x[7], n;int main() {//FOR(i1, 0, 6) FOR(i2, 0, 6) FOR(i3, 0, 6) FOR(i4, 0, 6) FOR(i5, 0, 6) FOR(i6, 0, 6)//if(a[i1][i2][i3][i4][i5][i6] < EPS) solve(i1, i2, i3, i4, i5, i6);while(scanf("%d", &n) != EOF && n) {memset(x, 0, sizeof(x));for(int i = 1; i <= n; ++i) scanf("%d", &x[i]);printf("%.6f\n", solve(x[1], x[2], x[3], x[4], x[5], x[6]));}
}

toj 4612 A Shooting Game相关推荐

  1. TOJ 1702.A Knight's Journey

    2015-06-05 问题简述: 有一个 p*q 的棋盘,一个骑士(就是中国象棋里的马)想要走完所有的格子,棋盘横向是 A...Z(其中A开始 p 个),纵向是 1...q. 原题链接:http:// ...

  2. 数集合有多少个TOJ(2469)

    题目链接:http://acm.tju.edu.cn/toj/showp2469.html 感觉这个题目有点问题,算了不管他了,反正A了. 这里要注意的是求这个集合有多少种,那么就是要剔除重复数后,再 ...

  3. toj 4604 搞笑版费马大定理

    toj 4604 搞笑版费马大定理 时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte 总提交: 122 测试通过:67 描述 费马大定理:当n>2时,不定方 ...

  4. toj 4601 好老师

    toj 4601 好老师 时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte 总提交: 73 测试通过:37 描述 我想当一个好老师,所以我决定记住所有学生的名字. ...

  5. toj 4597 字符识别?

    toj 4597 字符识别? 时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte 总提交: 122 测试通过:95 PS:最好是看原题,这里图案对齐不是那么好. 4 ...

  6. toj 4596 一行盒子

    toj 4596 一行盒子 时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte 总提交: 116 测试通过:11 描述 你有一行盒子,从左到右依次编号为1, 2, ...

  7. toj 4319 盒子游戏

    toj 4319 盒子游戏 时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte 总提交: 137 测试通过:76 描述 有两个相同的盒子,其中一个装了 n 个球,另 ...

  8. toj 4317 多连块拼图

    toj 4317 多连块拼图 时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte 总提交: 40 测试通过:21 描述 多连块是指由多个等大正方形边与边连接而成的平 ...

  9. toj 4316 报数游戏

    toj 4316 报数游戏 时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte 总提交: 68 测试通过:35 描述 n 个人站成一行玩一个报数游戏.所有人从左到右 ...

最新文章

  1. linux进程调度浅析
  2. Linux下出现Read-only file system的解决办法
  3. java反射 用处_浅谈Java反射
  4. pythonrequests发送数据_在python中使用requests 模拟浏览器发送请求数据的方法
  5. 浅谈 EF CORE 迁移和实例化的几种方式
  6. 牛客挑战赛47 A 一道GCD问题
  7. redis——客户端
  8. 高考考生已成不法分子觊觎“肥肉” 个人信息及财产成重点目标
  9. 解决MYSQL不报错误详细信息的问题 Can‘t find error-message file
  10. android项目模块导入eclipse编译报错,android环信demo导入eclipse编译出错
  11. P0INP = 0Xfd;P1DIR |= 0X01;
  12. qtp java_QTP Java swing 一些控件的遍历
  13. 如何让Java文件在虚拟机中运行_深入理解JVM--Java程序如何在虚拟机中运行
  14. Tesla特斯拉电动汽车电力驱动系统3D模型(含悬挂) Catia 附STEP
  15. linux上的ds命令,使用DS-5 进行Linux应用开发
  16. 2022工具钳工(高级)考试题模拟考试平台操作
  17. 家谱世系图一键生成家谱软件
  18. 世界十大名言是什么?
  19. 联想服务器pe进系统还原,传授联想如何一键还原系统
  20. 【读者来信】培训完没有类似的工作经验,该如何找工作?

热门文章

  1. C#函数(构造函数)的重载
  2. 【Nginx那些事】nginx原理解析
  3. Ubuntu16 python2.7升级python3.5
  4. 有人模仿我的脸,有人模仿我的话
  5. 文件从头开始读函数_如何从头开始编写自己的Promisify函数
  6. react hoc_如何使用HOC模式开发React超能力
  7. Java 环形缓冲器(Ring Buffer)
  8. oa工作流 源码_oa管理系统工作流是什么?类型、优势、功能有哪些?
  9. msys2安装gcc、g++编译器
  10. Python-关于正则表达式的总结