2017ACM/ICPC亚洲区沈阳站_Wandering Robots(hash)_马尔科夫链_随机游走

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define INF 0x3f3f3f3f
#define rep0(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define rep_0(i, n) for (int i = n - 1; i >= 0; i--)
#define rep_1(i, n) for (int i = n; i > 0; i--)
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#define mem(x, y) memset(x, y, sizeof(x))
#include <map>
#define MAXN (10000 + 10)
#define MAXK 1000
/**
题目大意
N * N的区域内,有K个格子不能到达,机器人从(0, 0)出发有均等的该概率
留在原地和到达上下左右可到达的区域,问无穷远的时间以后有多大概率到达
x + y >= n - 1 的区域
思路
计算除了不能到达的格子之外的格子能通往多少方向d,则格子的权值为d + 1
ans = x + y >= n - 1 的格子的权值之和 / 总权值和

*******************************************************

马尔科夫链的随机游走模型
可建立状态转移矩阵,对n * n 的图中n * n 个点编号为0 ~[ (n - 1) * n + n – 1]  设最大编号为max
P = p(i, j) = [p(0, 0) p(0, 1) … p(0, max)
               P(1, 0) p(1, 1) … p(1, max)
               …
               P(max, 0) p(max, 1) … p(max, max)]
π(i) 为i时间各点的概率
π(n + 1) = π(n) * P
当时间->无穷 π(n + 1)->π
可以通过 π * P = π 计算  
验证猜测结果正确

*******************************************************
找规律的答案 有待证明
现在能想到的是 整个封闭系统每个格子以出现机器人的概率作为权值 在很长的时间线上是一个熵增的
过程(想到元胞自动机),如果要模拟这个概率扩散的过程的话,格子的权值的更新是一个用他所能到达的格子的权值
和他自身的权值迭代的过程,这个过程中可以发现他的相邻的格子的权值是在不断同化的,因此,在无穷远后
(0, 0)的和他周围的格子的权值不在体现优势,而更加开放的格子则更占优(可根据迭代公式理解)

*/

using namespace std;
typedef long long LL;
int n, k;
map<LL, int> mp;
int dir[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int g[MAXK][2];
LL gcd(LL x, LL y)
{
    if (y == 0)
        return x;
    else return gcd(y, x % y);
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
    #endif // ONLINE_JUDGE
    int t, kase = 0;
    scanf("%d", &t);

    while(t--)
    {
        mp.clear();
        scanf("%d %d", &n, &k);
        LL a = 0, b = 0;
        if (n > 2)
        {
            a += (LL)(n - 2) * 4 * 2 + 3 * 3 + (LL)(n - 2) * (n - 1) / 2 * 5;
            b += 4 * 3 + (LL)(n - 2) * 4 * 4 + (LL)(n - 2) * (n - 2) * 5;
        }
        else
        {
            a += 3 * 3;
            b += 4 * 3;
        }
        //cout << a << "   " << b << endl;
        int x, y;
        for (int i = 0; i < k; i++)
        {
            scanf("%d %d", &x, &y);
            pair<LL, int> tmp;
            tmp.first = (LL)x * MAXN + y;
            tmp.second = i;
            mp.insert(tmp);

        }

        map<LL, int> :: iterator itr;
        map<LL, int> :: iterator itr1;
        for (itr = mp.begin(); itr != mp.end(); itr++)
        {
            x = (itr->first) / MAXN;
            y = (itr->first) % MAXN;
            int cnt = 0;
            for (int i = 0; i < 4; i++)
            {
                int nx = x + dir[i][0], ny = y + dir[i][1];
                if (nx < 0 || nx >= n || ny < 0 || ny >= n)
                    continue;

                cnt++;
                bool t = (itr1 = mp.find( (LL) nx * MAXN + ny) ) == mp.end();
                if (t && nx + ny >=  n - 1)
                {

                    b--;
                    a--;

                }
                else if (t)
                    b--;

            }

            b -= cnt + 1;
            if (x + y >= n - 1)
                a -= cnt + 1;
        }

        LL g = gcd(a, b);

        printf("Case #%d: %lld/%lld\n", ++kase, a / g, b / g);

    }

    return 0;
}



  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值