题目链接  HDU 6229

题意 在一个$N * N$的格子矩阵里,有一个机器人。

  格子按照行和列标号,左上角的坐标为$(0, 0)$,右下角的坐标为$(N - 1, N - 1)$

  有一个机器人,初始位置为$(0, 0)$。

  现在这个矩阵里面,有一些障碍物,也就是说机器人不能通过这些障碍物。

  若机器人当前位置为$(x, y)$,那么他下一个位置有可能为与当前格子曼哈顿距离为$1$的所有格子的任意1个。

  也有可能停留在原来的位置$(x, y)$

  求经过无限长的时间之后,这个机器人的位置在给定区域的概率。

  结果用分数表示。

  给定区域为$(x, y)$,满足 $x + y ≥ N - 1$

  题目满足无障碍区域是连通的

当时在现场,和Au的差距就是罚时和这道题。

结论其实很简单,但是赛场上因为思维僵化就是想不出来。

首先对于每个点,初始都有一个权值。

角落的权值为$3$,边上但不是角落的权值为$4$,其他点权值为$5$。

我们对每个障碍点进行处理。障碍点的权值直接赋值为$0$,障碍周围的点权值减$1$

由于开不下那么大的二维数组,所以对那些被操作过的点,我们用map记录。

最后把区域内的权值累加,除以整个矩形的权值和即为答案。

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b)	for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i)
#define MP make_pair
#define fi first
#define se second typedef long long LL;
typedef pair <int, int> PII; const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1}; int T;
int n, m; map < pair <int, int> , LL > mp;
int ca = 0; inline LL judge(int x, int y){
if ((x == 0 && y == 0) || (x == 0 && y == n - 1) || (x == n - 1 && y == 0) || (x == n - 1 && y == n - 1)) return 3;
if (x == 0 || x == n - 1 || y == 0 || y == n - 1) return 4;
return 5;
} inline bool check(int x, int y){
return (x + y) >= (n - 1);
} inline bool ok(int x, int y){
return x >= 0 && y >= 0 && x <= n - 1 && y <= n - 1;
} LL gcd(LL a, LL b){
return b == 0 ? a : gcd(b, a % b);
} int main(){ scanf("%d", &T);
while (T--){
scanf("%d%d", &n, &m);
LL all = 4 * 3 + (n - 2) * 4 * 4 + 5 * (n - 2) * (n - 2);
LL xx1 = 3, xx2 = 2 * (n - 2);
LL xx3 = n * (n + 1) / 2 - xx1 - xx2;
LL sum = xx1 * 3 + xx2 * 4 + xx3 * 5; mp.clear();
while (m--){
int x, y;
scanf("%d%d", &x, &y);
mp[MP(x, y)] = judge(x, y);
rep(i, 0, 3){
int nx = x + dx[i], ny = y + dy[i];
if (ok(nx, ny)){
++mp[MP(nx, ny)];
mp[MP(nx, ny)] = min(mp[MP(nx, ny)], judge(nx, ny));
}
} } for (auto cnt : mp){
int x = cnt.fi.fi, y = cnt.fi.se;
LL z = cnt.se;
if (check(x, y)) sum -= z;
all -= z;
} LL a1 = sum, a2 = all;
LL g = gcd(a1, a2);
a1 /= g, a2 /= g;
printf("Case #%d: %lld/%lld\n", ++ca, a1, a2);
} return 0;
}

  

HDU 6229 Wandering Robots(2017 沈阳区域赛 M题,结论)的更多相关文章

  1. hdu6229 Wandering Robots 2017沈阳区域赛M题 思维加map

    题目传送门 题目大意: 给出一张n*n的图,机器人在一秒钟内任一格子上都可以有五种操作,上下左右或者停顿,(不能出边界,不能碰到障碍物).题目给出k个障碍物,但保证没有障碍物的地方是强联通的,问经过无 ...

  2. Infinite Fraction Path HDU 6223 2017沈阳区域赛G题题解

    题意:给你一个字符串s,找到满足条件(s[i]的下一个字符是s[(i*i+1)%n])的最大字典序的长度为n的串. 思路:类似后缀数组,每次倍增来对以i开头的字符串排序,复杂度O(nlogn).代码很 ...

  3. hdu6223 Infinite Fraction Path 2017沈阳区域赛G题 bfs加剪枝(好题)

    题目传送门 题目大意:给出n座城市,每个城市都有一个0到9的val,城市的编号是从0到n-1,从i位置出发,只能走到(i*i+1)%n这个位置,从任意起点开始,每走一步都会得到一个数字,走n-1步,会 ...

  4. HDU 6229 - Wandering Robots - [概率题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6229 转载: https://blog.csdn.net/Anna__1997/article/det ...

  5. 2017沈阳区域赛Infinite Fraction Path(BFS + 剪枝)

    Infinite Fraction Path Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java ...

  6. HDU 6205 2017沈阳网络赛 思维题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6205 题意:给你n堆牌,原本每一堆的所有牌(a[i]张)默认向下,每次从第一堆开始,将固定个数的牌(b ...

  7. Heron and His Triangle 2017 沈阳区域赛

    A triangle is a Heron’s triangle if it satisfies that the side lengths of it are consecutive integer ...

  8. 2017乌鲁木齐区域赛D题Fence Building-平面图的欧拉公式

    这个题B站上面有这题很完整的分析和证明,你实在不懂,可以看看这个视频  https://www.bilibili.com/video/av19849697?share_medium=android&a ...

  9. 2017西安区域赛A / UVALive - 8512 线段树维护线性基合并

    题意:给定\(a[1...n]\),\(Q\)次询问求\(A[L...R]\)的异或组合再或上\(K\)的最大值 本题是2017的西安区域赛A题,了解线性基之后你会发现这根本就是套路题.. 只要用线段 ...

随机推荐

  1. 并查集:HDU5326-Work(并查集比较简单灵活的运用)

    Work HDU原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5326 Time Limit: 2000/1000 MS (Java/Others) M ...

  2. VBA连接到SQL2008需要加上端口号

    VBA连接到SQL2008需要加上端口号1433,比如 conn = "server=XXXX.XXXX.XXXX.XXXX,1433;provider=SQLOLEDB.1;databas ...

  3. loj2044 「CQOI2016」手机号码

    ref #include <iostream> #include <cstring> #include <cstdio> using namespace std; ...

  4. Set-DnsServerGlobalQueryBlockList

    Set-DnsServerGlobalQueryBlockList Windows Server Technical Preview and Windows 10   Other Versions   ...

  5. Oracle 分析函数--Row_Number()

    row_number() over ([partition by col1] order by col2) ) as 别名 表示根据col1分组,在分组内部根据 col2排序 而这个“别名”的值就表示 ...

  6. Redis 配置登录密码

    1. 通过配置文件进行配置 打开 redis.conf,找到 #requirepass foobared 去掉行前的注释,并修改密码为所需的密码,保存文件 重启redis sudo service r ...

  7. vue-devtools安装

    https://www.cnblogs.com/yuqing6/p/7440549.html

  8. c#中dynamic ExpandoObject的用法

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  9. alpha(4/10)

    目录 摘要 团队部分 个人部分 摘要 队名:小白吃 组长博客:hjj 作业博客:冲刺4 团队部分 后敬甲 过去两天完成了哪些任务 文字描述 主页部分图标的替换 -拍照按钮的设计和测试 GitHub代码 ...

  10. Excel的数据批量替换

    该篇文章照抄自:http://www.cnblogs.com/xwgli/p/5845317.html 在 Excel 中使用正则表达式进行查找与替换  在 Excel 中,使用 Alt+F11 快捷 ...