题目链接  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. [NOIP2012]疫情控制(二分答案+倍增+贪心)

    Description H国有n个城市,这n个城市用n-1条双向道路相互连通构成一棵树,1号城市是首都,也是树中的根节点. H国的首都爆发了一种危害性极高的传染病.当局为了控制疫情,不让疫情扩散到边境 ...

  2. 回顾Scrum学习:《Scrum实战》第4次课【全职的Scrum Master】作业

    回顾Scrum学习   1.回顾目标 1.1 期望结果 了解和学习Scrum,为将来换方向打好理论基础 如果能在目前公司引入和推行也很好,但是根据目前公司的文化氛围来看,推行希望不大 把敏捷思想应用到 ...

  3. mysql中外联和 is null 结合使用

    今天学习mysql ,碰到了一个问题:有部门表,员工表,员工表中有一个部门表的外键,查询没有员工的部门名称. 表结构如下: 员工表employees: 部门表department表: 题目很简单呢,信 ...

  4. 微信SSL证书更换的检查与安装方法

    Ubuntu, Debian 查看根证书 确认操作系统上,是否存在以下文件: /etc/ssl/certs/DigiCert_Global_Root_CA.pem /etc/ssl/certs/Bal ...

  5. loj2308 「APIO2017」商旅

    ref #include <iostream> #include <cstring> #include <cstdio> #include <queue> ...

  6. loj2043 「CQOI2016」K 远点对

    k-d tree 裸题------ #include <algorithm> #include <iostream> #include <cstdio> using ...

  7. Group Policy Object Editor

    Group Policy Object Editor   The Group Policy Object Editor is a tool that hosts MMC extension snap- ...

  8. 【清华集训】小Y和地铁

    图已挂,前往luogu 题目: 小 $\rm Y$ 是一个爱好旅行的 $\rm OIer$.一天,她来到了一个新的城市.由于不熟悉那里的交通系统,她选择了坐地铁.她发现每条地铁线路可以看成平面上的一条 ...

  9. 数据库——初始mysql语句(2)

    sql语句 #1. 操作文件夹(库) 增:create database db1 charset utf8; 查:show create database db1; show databases; 改 ...

  10. python 使用 vscode 调试

    vscode安装python扩展,在vscode扩展管理器中搜索pyhon, 排名第一的就是我们需要下载的包—python.点击安装后重载窗体 点击调试–打开launch.json的按钮(那个小齿轮的 ...