HDU-6229 ICPC-沈阳M- Wandering Robots 概率
题意:
在一个n*n的地图中,有一个初始在(0,0)位子的机器人,每次等概率的向相邻的格子移动或者留在原地。问最后留在格子(x,y)(x+y>=n-1)的地方的概率。
思路:
这道题由于每个格子的贡献是不同的,在四个角格子的贡献是3分(留下来,两个边来的),中间的5分,有一条边与边相连的4分。如果这个点是障碍物,则把这个点的贡献抹为0,再把其四周的格子贡献-1.
由于开不下数组,可以用map
// #pragma GCC optimize(3)
// #pragma comment(linker, "/STACK:102400000,102400000") //c++
// #pragma GCC diagnostic error "-std=c++11"
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert>
#include <map> using namespace std;
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 bll;
typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int,pii> p3; //priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n' #define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A) //用来压行
#define REP(i , j , k) for(int i = j ; i < k ; ++i)
#define max3(a,b,c) max(max(a,b), c);
//priority_queue<int ,vector<int>, greater<int> >que; const ll mos = 0x7FFFFFFF; //
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x7f7f7f7f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //
const int mod = 1e8+;
const double esp = 1e-;
const double PI=acos(-1.0);
const double PHI=0.61803399; //黄金分割点
const double tPHI=0.38196601; template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
} /*-----------------------showtime----------------------*/
map<pii,int>mp;
int nx[][] = {
{,}, {,} ,{-,},{,-}
};
int T,n,k;
int get(int x,int y){
if(x>&&x<n- && y> && y<n-)
return ;
if(x==&&y==)return ;
if(x==n-&&y==)return ;
if(x==&&y==n-)return ;
if(x==n-&&y==n-)return ;
return ;
}
ll gcd(ll a, ll b){
if(b == )return a;
return gcd(b, a % b);
}
int main(){
scanf("%d", &T);
for(int tt=; tt<=T; tt++){
mp.clear();
scanf("%d%d", &n, &k);
if(n == ){
printf("Case #%d: 1/1\n", tt);
continue;
} ll sum = *+(n-)**+(n-)*(n-)*;
ll dec = ;
ll up = *+(n-)**+(n-)*(n-)/*; for(int i=; i<=k; i++){
int x,y;
scanf("%d%d", &x, &y); for(int i=; i<; i++){
int tx = x + nx[i][];
int ty = y + nx[i][];
if(tx < || tx >= n||ty<||ty>=n)continue;
if(mp.count(pii(tx,ty))){
if(mp[pii(tx,ty)] == )continue;
mp[pii(tx,ty)] --;
if(tx + ty >= n-)up--;
sum--;
}
else {
mp[pii(tx,ty)] = get(tx,ty) - ;
if(tx + ty >= n-)up--;
sum--;
}
}
if(mp.count(pii(x,y))) {
if(mp[pii(x,y)] == )continue;
if(x + y >= n-)up -= mp[pii(x,y)];
sum -= mp[pii(x,y)];
mp[pii(x,y)] = ;
}
else{
mp[pii(x,y)] = ;
if(x + y >= n-)up -= get(x,y);
sum -= get(x,y);
}
}
ll gg = gcd(up, sum);
printf("Case #%d: %lld/%lld\n", tt, up/gg, sum/gg); // for(int i=0; i<n; i++){
// for(int j=0; j<n; j++){
// if(mp.count(pii(i,j)))
// cout<<i<<" , "<<j<<"="<<mp[pii(i,j)]<<endl;
// }
// cout<<endl;
// }
} return ;
}
HDU - 6229
HDU-6229 ICPC-沈阳M- Wandering Robots 概率的更多相关文章
- HDU 6229 - Wandering Robots - [概率题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6229 转载: https://blog.csdn.net/Anna__1997/article/det ...
- HDU 6229 Wandering Robots(2017 沈阳区域赛 M题,结论)
题目链接 HDU 6229 题意 在一个$N * N$的格子矩阵里,有一个机器人. 格子按照行和列标号,左上角的坐标为$(0, 0)$,右下角的坐标为$(N - 1, N - 1)$ 有一个机器人, ...
- hdu6229 Wandering Robots 2017沈阳区域赛M题 思维加map
题目传送门 题目大意: 给出一张n*n的图,机器人在一秒钟内任一格子上都可以有五种操作,上下左右或者停顿,(不能出边界,不能碰到障碍物).题目给出k个障碍物,但保证没有障碍物的地方是强联通的,问经过无 ...
- 2018 ICPC 沈阳网络赛
2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex H ...
- ACM-ICPC 2017 沈阳赛区现场赛 M. Wandering Robots && HDU 6229(思维+期望)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6229 参考题解:https://blog.csdn.net/lifelikes/article/det ...
- 【概率】【找规律】hdu6229 Wandering Robots
题意:一个机器人在正方形迷宫的左上角,迷宫里有些格子有障碍物,每一步机器人会等概率地向能走的格子转移(包含自身).问你无限长的时间之后,机器人处于矩形对角线的右下方的概率. 无限长时间意味着,起点没有 ...
- HDU 5894 hannnnah_j’s Biological Test (组合数学) -2016 ICPC沈阳赛区网络赛
题目链接 #include <map> #include <queue> #include <math.h> #include <stdio.h> #i ...
- HDU 5898 odd-even number (数位DP) -2016 ICPC沈阳赛区网络赛
题目链接 题意:一个数字,它每个数位上的奇数都形成偶数长度的段,偶数位都形成奇数长度的段他就是好的.问[L , R]的好数个数. 题解:裸的数位dp, 从高到低考虑每个数位, 状态里存下到当前位为止的 ...
- HDU 5901 Count primes (1e11内的素数个数) -2016 ICPC沈阳赛区网络赛
题目链接 题意:求[1,n]有多少个素数,1<=n<=10^11.时限为6000ms. 官方题解:一个模板题, 具体方法参考wiki或者Four Divisors. 题解:给出两种代码. ...
随机推荐
- 【WPF】 InkCanvas 书写毛笔效果
首先贴出本文参考学习的文章吧. https://www.cnblogs.com/LCHL/p/9055642.html#4206298 感谢这位懒羊羊的代码和讲解(下简称羊博主),我在此基础上稍微加了 ...
- Iterator-Java
在Java中,Iterator的作用就是为了方便处理集合中的元素.例如获取和删除集合中的元素. 在JDK8,Iterator接口提供了如下方法: 迭代器Iterator最基本的两个方法是next()和 ...
- oracle的开窗函数
原创 select * from (select province, commodity, sum(price), ROW_NUMBER() OVER(PARTITION BY province o ...
- 国内CDH的MAVEN代理
在编译CDH版本的各个开源软件时,需要从cdh-repo下载对应的jar包,但发现下载速度非常慢,甚至有时候出现下载异常的情况. 下面是国内可用的.速度非常快的一个maven代理仓库,亲测可用: ht ...
- 01-Spring Security框架学习--入门(二)
一.入门案例 Spring Security 自定义登录界面 通过之前的一节 01-Spring Security框架学习--入门(一)的简单演示,Spring security 使用框架自带的登录界 ...
- 9、数组中删除元素(test6.java)
前文讲到,通过函数,进行数组元素的添加,这里同样通过这个函数,进行数组的删除. 举个例子,代码如下: //导入输入所需要的包 import java.util.Scanner; public clas ...
- webgl核心要素
WebGL是一种3D绘图标准,这种绘图技术标准允许把JavaScript和OpenGL ES 2.0结合在一起,通过增加OpenGL ES 2.0的一个JavaScript绑定,提供硬件3D加速渲染, ...
- 分享一个非常好用又好看的终端工具--Hyper (支持windows、MacOS、Linux)
分享一个非常好用又好看的终端工具--Hyper 官网地址: https://hyper.is/ 打开官网,选择对应版本安装即可:(可能网络原因,无法下载, 可以从我分享的链接下载 链接: https: ...
- openldap介绍和使用
openldap介绍和使用 为什么会有本文? 早期,公司是没有统一认证这个东西的,所以各自玩各自的.于是, confluence一个用户体系,gitlab一个用户体系,Jenkins一个用户体系等等, ...
- 逛公园[NOIP2017 D2 T3](dp+spfa)
题目描述 策策同学特别喜欢逛公园. 公园可以看成一张 \(N\)个点\(M\) 条边构成的有向图,且没有自环和重边.其中 1号点是公园的入口,N号点是公园的出口,每条边有一个非负权值,代表策策经过这条 ...