HDU - 6229

题意:

  在一个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 概率的更多相关文章

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

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

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

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

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

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

  4. 2018 ICPC 沈阳网络赛

    2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex H ...

  5. ACM-ICPC 2017 沈阳赛区现场赛 M. Wandering Robots && HDU 6229(思维+期望)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6229 参考题解:https://blog.csdn.net/lifelikes/article/det ...

  6. 【概率】【找规律】hdu6229 Wandering Robots

    题意:一个机器人在正方形迷宫的左上角,迷宫里有些格子有障碍物,每一步机器人会等概率地向能走的格子转移(包含自身).问你无限长的时间之后,机器人处于矩形对角线的右下方的概率. 无限长时间意味着,起点没有 ...

  7. HDU 5894 hannnnah_j’s Biological Test (组合数学) -2016 ICPC沈阳赛区网络赛

    题目链接 #include <map> #include <queue> #include <math.h> #include <stdio.h> #i ...

  8. HDU 5898 odd-even number (数位DP) -2016 ICPC沈阳赛区网络赛

    题目链接 题意:一个数字,它每个数位上的奇数都形成偶数长度的段,偶数位都形成奇数长度的段他就是好的.问[L , R]的好数个数. 题解:裸的数位dp, 从高到低考虑每个数位, 状态里存下到当前位为止的 ...

  9. HDU 5901 Count primes (1e11内的素数个数) -2016 ICPC沈阳赛区网络赛

    题目链接 题意:求[1,n]有多少个素数,1<=n<=10^11.时限为6000ms. 官方题解:一个模板题, 具体方法参考wiki或者Four Divisors. 题解:给出两种代码. ...

随机推荐

  1. js函数柯理化

    所谓的函数柯理化,简单来说就是,一个需要接收多个参数的函数,进行分开一个个的传递参数,当函数执行的时候,传递剩余的参数. 主要作用在于增强函数的通用性. 如下举个例子: function custom ...

  2. spring 的权限控制:security

    下面我们将实现关于Spring Security3的一系列教程. 最终的目标是整合Spring Security + Spring3MVC 完成类似于SpringSide3中mini-web的功能. ...

  3. Web前端开发——Ionic 3.0【爱创课堂专业前端培训】

    前端开发——Ionic 3.0 一.Ionic 移动端有三种开发方向 源生APP开发, 移动端web开发 混合开发(介于以上两者之间的) 类微信小程序 reactNative,用react语法,开发a ...

  4. c#异常后重试操作

    private void TryConnect(System.Action action)         {             int retries = 3;             whi ...

  5. 1、大型项目的接口自动化实践记录--robotframework环境搭建

    因为人力.团队技术问题,选用robotframework来做自动化,首先说下环境搭建 齐涛道长的入门教程非常棒:http://blog.csdn.net/tulituqi/article/detail ...

  6. 记录用友T+接口对接的心酸历程

    前言:公司的业务主要是对接财务系统做单据传输或者凭证处理的,难免少不了和各大财务软件做数据对接,其中当然是必须通过接口来传递数据了.于是乎,用友T+的版本来了,对接的工作自然是我来做,可没想到就是这样 ...

  7. 图像反转(一些基本的灰度变换函数)基本原理及Python实现

    1. 基本原理 获取像素值在[0, L]范围内的图像的反转图像,即为负片.适用于增强图像中白色或者灰色的区域,尤其当黑色在图片中占主地位时候 $$T(r) = L-r$$ 2. 运行结果 图源自ski ...

  8. java虚拟机学习笔记(五)---运行时的数据区域

    Java虚拟机所管理的内存包括以下几个运行时的数据区域:方法区,堆,虚拟机栈,本地方法栈,程序计数器.下面对其进行介绍: 程序计数器 它是一块较小的内存空间,可以看做当前线程做执行的字节码的信号指示器 ...

  9. hadoop学习(一)----概念和整体架构

    程序员就得不停地学习啊,故步自封不能满足公司的业务发展啊!所以我们要有搞事情的精神.都说现在是大数据的时代,可以我们这些码农还在java的业务世界里面转悠呢.好不容易碰到一个可能会用到大数据技术的场景 ...

  10. 不相交路径[BZOJ1471] 容斥原理 拓扑排序

    最近学容斥的时候又碰到一道类似的题目,所以想分享一个套路,拿这题来举例 [题目描述] 给出一个\(N(N\leq 150)\)个结点的有向无环简单图.给出4个不同的点\(a,b,c,d\),定义不相交 ...