题意

一个\(n \times m\)的矩形空间,起点是\((1,1)\),终点是\((n,m)\)。

假设当前位于\((x,y)\):

  • 如果当前位于最后一行,那么下一步只能走向\((x,y+1)\)
  • 如果当前位于最后一列,那么下一步只能走向\((x+1,y)\)
  • 否则,以相等的概率走向\((x,y+1)\)和\((x+1,y)\)中的一个。

矩形空间中有一个小的矩形黑洞,用左上角和右下角的坐标表示,走进黑洞视为游戏失败,走到\((n,m)\)视为游戏成功,问游戏成功的概率。

解题思路

先不考虑黑洞。

对于\(1 \leq x < n, 1 \leq y < m\),走到\((x,y)\)一共有\(C_{x+y-2}^{x-1}\)种可能的路径,然后走每一条可能的路径的概率为\(\frac{1}{2^{x+y-2}}\),所以走到\((x,y)\)的概率是\(\frac{C_{x+y-2}^{x-1}}{2^{x+y-2}}\)。

但是\(n,m\)的取值最高可以到\(1e5\),如果不加处理会炸精度,如果使用\(\log\)处理就可以把数值压在能接受的范围内。再加上

\[2^{\log(\frac{C_{x+y-2}^{x-1}}{2^{x+y-2}})} = 2 ^ {\log((x + y - 2)!)-\log((y-1)!) - -\log((x-1)!) - x -y +2}
\]

\(O(n)\)预处理出\(\log(i!)\)后就可以方便的计算\(P(x,y)\)了。

然后根据规则,最后一行和最后一列的概率要另外算。这里仅以最后一行为例,最后一列也是用同样的方法。

记走到\((x,y)\)的概率为\(P(x,y)\),那么如果\((x,y)\)位于最后一行,则\(P(x,y)=P(x,y-1)+\frac{1}{2}P(x-1,y)\)。然后\(P(1,n)\)很容易推出等于\(\frac{1}{2^{n-1}}\),所以这一行的概率就可以\(O(n)\)的递推出来。

假设上图中,黑色部分为黑洞,\((1,1)\)位于坐上角,那么很容易就可以得出游戏成功的概率为走到灰色格子的概率之和。将之前推导出的公式代入即可。

总结

早上七点的比赛差点错过了。前三题几乎都是直接秒,但是卡在了第四题。公式都推对了,但是没有想到炸精度怎么处理。脑海中出现了之前llg想在学校月赛搞用log处理大数的出题思路,但是看精度一直觉得不太行,然后就下班了,哪想到这就是正解。果然有时候就应该xjbg。

然后补题的时候又是因为担心精度问题用了long double,然后各种TLE,换成double就过了。

AC代码

#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5; double lg[N], lstr[N], lstc[N];
int main()
{
#ifdef BACKLIGHT
freopen("in.txt", "r", stdin);
#endif lg[0] = 0;
for (int i =1; i <= 2e5; ++i) lg[i] = lg[i-1] + log2(i); int T;
scanf("%d", &T);
for (int Case = 1; Case <= T; Case ++) {
int n, m, l, r, u, d;
scanf("%d %d %d %d %d %d", &n, &m, &l, &u, &r, &d); lstr[1] = pow(2, lg[1 + n - 2] - lg[1 - 1] - lg[n - 1] - 1 - n + 2);
for (int i = 2; i <= m; i++) {
lstr[i] = lstr[i-1] + 0.5 * pow(2, lg[i + (n-1)- 2] - lg[i - 1] - lg[(n-1) - 1] - i - (n-1) + 2);
} lstc[1] = pow(2, lg[1 + m - 2] - lg[1 - 1] - lg[m - 1] - 1 - m + 2);
for (int i = 2; i <= n; i++) {
lstc[i] = lstc[i-1] + 0.5 * pow(2, lg[i + (m-1)- 2] - lg[i - 1] - lg[(m-1) - 1] - i - (m-1) + 2);
} double ans = 0, tmp;
for (int i = 1; i <= l - 1; ++i) {
int D = l + d - i;
if(D > m) continue;
else if(D == m) {
ans += lstc[i];
}
else {
tmp = lg[i + D - 2] - lg[i - 1] - lg[D - 1] - i - D + 2;
ans += pow(2, tmp);
}
} for (int i = 1; i <= u - 1; ++i) {
int R = r + u - i;
if(R > n) continue;
else if(R == n) {
ans += lstr[i];
}
else {
tmp = lg[i + R - 2] - lg[i - 1] - lg[R - 1] - i - R + 2;
ans += pow(2, tmp);
}
} printf("Case #%d: %.12lf\n", Case, ans);
}
return 0;
}

Google Kick Start 2020 Round B T4 Wandering Robot的更多相关文章

  1. Google Kick Start 2020 Round B T1-3

    这场题目除了最后一题稍微难了点,其他都是1眼题. T1 Bike Tour 没啥好说的,一个循环解决. T2 Bus Routes 没啥好说的,从第\(n\)的车站开始贪心取最晚的. T3 Robot ...

  2. Google Kick Start 2020 Round C

    ac代码 A. Countdown for循环跑一跑,没啥好说的. B. Stable Wall 如果\(s_{i,j} \ne s_{i+1,j}\),那么说明\(s_{i+1,j}\)必须在\(s ...

  3. Google Kick Start Round G 2019

    Google Kick Start Round G 2019 Book Reading 暴力,没啥好说的 #include<bits/stdc++.h> using namespace s ...

  4. Google Kick Start 2019 C轮 第一题 Wiggle Walk 题解

    Google Kick Start 2019 C轮 第一题 Wiggle Walk 题解 题目地址:https://codingcompetitions.withgoogle.com/kickstar ...

  5. [C++]Store Credit——Google Code Jam Qualification Round Africa 2010

    Google Code Jam Qualification Round Africa 2010 的第一题,很简单. Problem You receive a credit C at a local ...

  6. Google Code Jam 2010 Round 1C Problem A. Rope Intranet

    Google Code Jam 2010 Round 1C Problem A. Rope Intranet https://code.google.com/codejam/contest/61910 ...

  7. kick start 2019 round D T3题解

    ---恢复内容开始--- 题目大意:共有N个房子,每个房子都有各自的坐标X[i],占据每个房子需要一定花费C[i].现在需要选择K个房子作为仓库,1个房子作为商店(与题目不同,概念一样),由于仓库到房 ...

  8. dp - Google Code jam Qualification Round 2015 --- Problem B. Infinite House of Pancakes

    Problem B. Infinite House of Pancakes Problem's Link:   https://code.google.com/codejam/contest/6224 ...

  9. Google Code jam Qualification Round 2015 --- Problem A. Standing Ovation

    Problem A. Standing Ovation Problem's Link:   https://code.google.com/codejam/contest/6224486/dashbo ...

随机推荐

  1. 嵌入式linux下获取flash分区大小

    在嵌入式系统中,由于flash存储空间有限,或者是存储数据,实现数据的循环删除,需要获取到分区的使用情况,可以通过系统下的函数statfs来获取使用情况:实现代码如下: flashInfo.cpp # ...

  2. intellij idea springboot无法读取配置文件的解决方法

    问题描述 Spring Boot项目中运行之后,出现如下的错误: *************************** APPLICATION FAILED TO START *********** ...

  3. 会话机制,Cookie和Session详解

    转载自:https://www.cnblogs.com/whgk/p/6422391.html 很大一部分应该知道什么是会话机制,也能说的出几句,我也大概了解一点,但是学了之后几天不用,立马忘的一干二 ...

  4. Prometheus Operator 教程:根据服务维度对 Prometheus 分片

    原文链接:https://fuckcloudnative.io/posts/aggregate-metrics-user-prometheus-operator/ Promtheus 本身只支持单机部 ...

  5. Centos系统安装Python3.7

    服务器安装Python3.7,实测可用 原博客地址 首先要先安装依赖包: yum install zlib-devel bzip2-devel openssl-devel ncurses-devel ...

  6. 【IDE】WebStorm 调整Tab缩进为2空格 -- 为遵循ESLint语法规范

    步骤一 修改这三处的值为:2 步骤二 把这两处默认的勾选去掉,不让其detection当前文件的Tab缩进 注意! 通过上面两个步骤,我们只是改变了在JS文件的Tab缩进改为2个空格 但是,*.vue ...

  7. python中操作csv文件

    python中操作csv文件 读取csv improt csv f = csv.reader(open("文件路径","r")) for i in f: pri ...

  8. 【算法•日更•第二十八期】图论:强连通+Tarjan算法(一)

    ▎前言 一直都想学习这个东西,以为很难,结果发现也不过如此. 只要会些图论的基础就可以了. ▎强连通 ☞『定义』 既然叫强连通,那么一定具有很强的连通性. 强连通:就是指在一个有向图中,两个顶点可以互 ...

  9. Arraylist的源码学习

    @ 目录 ArrayList简介 ArrayList核心源码 ArrayList源码分析 System.arraycopy()和Arrays.copyOf()方法 两者联系与区别 ArrayList ...

  10. VUE 中引入百度地图(vue-Baidu-Map)

    1.安装 $ npm install vue-baidu-map --save 2.全局注册,在main.js中引入以下代码 import BaiduMap from 'vue-baidu-map' ...