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. TIJ学习--RTTI(Runtime-Time Type Identification)

    TIJ学习--RTTI(Runtime-Time Type Identification) RTTI 运行时类型检查机制 获取一个类的Class引用的三种方法 class TestClass{} Te ...

  2. java中dao层和service层的区别是什么

    dao层中已经有操作数据库的方法了,为什么还要service层去封装?有什么好处? tanghui12321 | 浏览 131990 次  我有更好的答案  推荐于2017-10-06 18:44:5 ...

  3. maven的编译规范

    maven的中央仓库上的jar的包名必须小写.否则maven编译不通过. 如:Memcached-Java-Client-3.0.2 的jar包. 目录如下: com.whalin.memcached ...

  4. 封装 Gson 解析Json到对象是否失败

    在使用Google的 Gson 类库解析 Json 数据时,难免会出现解析失败的情况. 在这种情况下,使用 if(obj == null) 是不可行的,fromJson 方法会自动生成对象的实例,所以 ...

  5. JDK1.8源码分析03之idea搭建源码阅读环境

    序言:上一节说了阅读源码的顺序,有了一个大体的方向,咱们就知道该如何下手.接下来,就要搭建一个方便阅读源码及debug的环境.有助于跟踪源码的调用情况. 目前新开发的项目, 大多数都是基于JDK1.8 ...

  6. java支付宝app支付-代码实现

    1.我们需要在支付宝商户平台配置好,取到四个参数如下(这是支付宝官方配置地址):https://www.cnblogs.com/fuzongle/p/10217144.html 合作身份者ID:123 ...

  7. java多线程基础(二)--java线程各状态关系

    注意只有可运行(就绪态)和运行中(运行态)可以相互转换

  8. HlpViewer.exe 单独打开

    1.在桌面新建一个快捷键 2.添加HlpViewer.exe 的本地地址 3.在添加的地址后面添加 /catalogName VisualStudio12 4.保存快捷键即可 列: 桌面右键-> ...

  9. Go类型别名与类型定义区别

    类型别名和自定义类型区别 自定义类型 //自定义类型是定义了一个全新的类型 //将MyInt定义为int类型 type MyInt int 类型别名 //类型别名规定:TypeAlias只是Type的 ...

  10. 消息中间件——RabbitMQ(五)快速入门生产者与消费者,SpringBoot整合RabbitMQ!

    前言 本章我们来一次快速入门RabbitMQ--生产者与消费者.需要构建一个生产端与消费端的模型.什么意思呢?我们的生产者发送一条消息,投递到RabbitMQ集群也就是Broker. 我们的消费端进行 ...