题目传送门

题目大意:

给出一张n*n的图,机器人在一秒钟内任一格子上都可以有五种操作,上下左右或者停顿,(不能出边界,不能碰到障碍物)。题目给出k个障碍物,但保证没有障碍物的地方是强联通的,问经过无限长的时间后,停留在所有(x,y)(x+y>=n-1)的概率有多大。

思路:

概论题看上去很恐怖,但其实想到了就很简单。

先考虑没有障碍物的情况,由于是无限长的时间,那么最开始的时间机器人的走法是不会影响最终答案的,所以经过比较短的时间后,机器人可以出现在图上的任意地方,在这个时候到下一秒,机器人在不同格子能操作的数量是一个类似下面这个矩阵,而对于一个格子,能到这个格子的情况也是下面这个矩阵。

34443

45554

45554

45554

34443

也就是说,到下一秒的总情况数量就是上面这个矩阵的sum,合法的区域就是右下角这块的sum,在没有障碍物的情况下,概率就是这样了。

现在考虑上障碍物,一个格子放上障碍物,如果他旁边的格子没有障碍物,那么总情况就减少从其他格子到这个格子的情况,和从这个格子到其他格子的情况,如果旁边有障碍物,则不会有从其他格子到这个格子的情况,所以只要减去本身就可以了(事实上,没有减去这个1是因为在计算旁边的障碍物时已经减去了)。也就是分母减去(self+tot),tot为旁边的障碍数。

最后算一下gcd就可以了。

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string.h>
#include<sstream>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
#define CLR(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
inline int rd() {
int f = ;
int x = ;
char s = getchar();
while (s<'' || s>'') {
if (s == '-')f = -;
s = getchar();
}
while (s >= ''&&s <= '') {
x = x * + s - '';
s = getchar();
}
x *= f;
return x;
}
ll n,p,q;
inline ll gcd(ll a,ll b) {
if(b==)return a;
return gcd(b,a%b);
}
int k;
map<pair<int ,int >,int >mp;
int fx[][]= {{,},{,-},{,},{-,}};
int check(int x,int y) {
if((x==||x==n-)&&(y==||y==n-)) return ;
if((x==||x==n-)&&(y!=&&y!=n-)) return ;
if((y==||y==n-)&&(x!=&&x!=n-)) return ;
return ;
}
int main() {
int x,y;
int T,cas=;
cin>>T;
while(T--) {
scanf("%lld%d",&n,&k);
mp.clear();
p=((*)+((n-)**)+(n-)*(n-)*); //分母
q=((*)+((n-)**)+((n-)*(n-)/*)); //分子
while(k--) {
scanf("%d%d",&x,&y);
mp[make_pair(x,y)]=;
}
for(auto it:mp) {
x=it.first.first;
y=it.first.second;
p-=check(x,y);
if( x + y >= n - )q -= check(x,y);
for(int i=; i<; i++) {
int xx = x + fx[i][],yy = y+fx[i][];
if(xx<||yy<||xx>=n||yy>=n)continue;
if(!mp.count(make_pair(xx,yy))) {
p -= ;
if(xx + yy >= n-) {
q -= ;
}
}
}
}
ll g=gcd(p,q);
printf("Case #%d: %lld/%lld\n",cas++,q/g,p/g);
}
}

Wandering Robots

Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 466    Accepted Submission(s): 239

Problem Description
In an attempt to colonize Mars, some scientists were tasked with cleaning the planet. A cleaning robot, Marsba,was build with a huge restricted area in the Mars as a massive N × N square grid with K (K ≤ 1000) impassable barriers. This area are numbered from (0, 0) to (N - 1, N - 1) sequentially from left to right, row by row, where N ≤ 10000. The starting point of Marsba is situated on the top left corner lattice (0, 0). Marsba had instructions to program him with equal probability of remaining in the same lattice or travelling to an adjacent one. (Two lattices are said to be adjacent if they share a common edge.) This meant an equal probability being split equally between remaining in the lattice and the number of available routes. Specifically, for the lattice Marsba located in which has d adjacent lattices without impassable barriers, the probability for Marsba of remaining in the lattice or travelling to any adjacent lattice is \frac{1}{d+1} .
Then, those scientists completely forgot about it.
Many millennia ago, a young man realizes the importance of the cleaning robot, Marsba, at the end of the forgotten.
For further research, he asks you to calculate the probability of Marsba’s location (x, y) satisfying x + y ≥ N - 1.
Let the probability be an irreducible fraction of the form p/q, you should output p and q respectively, with a fraction slash as the separator.
 
Input
The first line of the input contains an integer t (t ≤ 1000) specifying the number of test cases.
For each case, the first line contains two positive integers N and K. Each of the next K lines contains the coordinate of a barrier.
Note that the starting point (0, 0) has no barrier and all test cases guarantee the connectivity of all lattices free of barriers.
 
Output
For each case output its label first, then output the probability as an irreducible fraction.
 
Sample Input
5
3 0
3 1
1 1
3 2
1 1
2 2
3 3
1 1
1 2
2 2
5 4
1 1
1 2
2 3
3 2
 
Sample Output
Case #1: 2/3
Case #2: 5/8
Case #3: 10/19
Case #4: 7/16
Case #5: 43/71

hdu6229 Wandering Robots 2017沈阳区域赛M题 思维加map的更多相关文章

  1. HDU 6229 Wandering Robots(2017 沈阳区域赛 M题,结论)

    题目链接  HDU 6229 题意 在一个$N * N$的格子矩阵里,有一个机器人. 格子按照行和列标号,左上角的坐标为$(0, 0)$,右下角的坐标为$(N - 1, N - 1)$ 有一个机器人, ...

  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. 2017沈阳区域赛Infinite Fraction Path(BFS + 剪枝)

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

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

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

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

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

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

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

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

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

  9. HDU-5532//2015ACM/ICPC亚洲区长春站-重现赛-F - Almost Sorted Array/,哈哈,水一把区域赛的题~~

    F - Almost Sorted Array Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

随机推荐

  1. junit4新框架hamcrest的assertThat

    assertThat JUnit4.4引入了Hamcrest框架,Hamcest提供了一套匹配符Matcher,这些匹配符更接近自然语言,可读性高,更加灵活 /**equalTo匹配符断言被测的tes ...

  2. eclipse中。安装findbugs java检测工具

    问题提出: 当我们编写完代码,做完单元测试等各种测试后就提交正式运行,只能由运行的系统来检测我们代码是否有问题了,代码中隐藏的错误在系统运行的过程中被发现后,然后再来进行相应的修改,那么后期修改的代价 ...

  3. 第4章 springboot热部署 4-1 SpringBoot 使用devtools进行热部署

    /imooc-springboot-starter/src/main/resources/application.properties #关闭缓存, 即时刷新 #spring.freemarker.c ...

  4. Ros学习——创建ROS消息和ROS服务

    1.rosed rosed 是 rosbash 的一部分.利用它可以直接通过package名来获取到待编辑的文件而无需指定该文件的存储路径了. rosed默认的编辑器是vim.修改其他的,打开~/.b ...

  5. Data Mining: SSE,MSE,RMSE,R-square指标讲解

    转载自:http://blog.csdn.net/l18930738887/article/details/50629409 SSE(和方差.误差平方和):The sum of squares due ...

  6. C#.NET中Dns类的常用方法及说明

    IP是一种普遍应用于因特网.允许不同主机能够相互找到对方的寻址协议.IP地址由4个十进制的数字号码所组成,而每一个号码的值介于0~255之间,它虽然解决了网络上计算机的识别问题,但是IP地址确不容易记 ...

  7. 40、inner mate distance for paired reads in a bam file

    参考:https://www.biostars.org/p/106291/#106344 1.inner mate distance : the distance from the right mos ...

  8. EZOJ #80

    传送门 分析 经典的树型DP 我们记录dp[i][0/1]表示i的子树中到i的长度分别为偶数和奇数的长度和 dp2[i][0/1]则表示不在i的子树中的点到i的长度分别为偶数和奇数的长度和 然后根据边 ...

  9. Edison UVALive3488

    传送门 题目大意 有一个0~n-1的序列,有m次操作,操作包含三个元素:pl,len,ti,表示这个操作进行ti次,每次将从pl+1开始的len个元素移到序列头部.分析 看到题不难想到使用平衡树将需移 ...

  10. Netty中的Future

    先看下Future的整个继承体系,还有一个ChannelFuture不在里面:     在并发编程中,我们通常会用到一组非阻塞的模型:Promise,Future 和 Callback.其中的 Fut ...