1. 程式人生 > >2017ACM/ICPC亞洲區瀋陽站_Wandering Robots(hash)_馬爾科夫鏈_隨機遊走

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;
}



相關推薦

2017ACM/ICPC亞洲區瀋陽_Wandering Robots(hash)__隨機

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #define INF

2017ACM/ICPC亞洲區瀋陽(部分解題報告)

HDU 6225 Little Boxes 題意 計算四個整數的和 解題思路 使用Java大整數 1 import java.math.BigInteger; 2 import java.util.Scanner; 3 4 /** 5 * 6 * @author reqaw

hdu6223Infinite Fraction Path(2017ACM/ICPC亞洲區瀋陽G題) 【BFS+剪枝】

傳送門:http://acm.hdu.edu.cn/showproblem.php?pid=6223 The ant Welly now dedicates himself to urban infrastructure. He came to the kingdom of numbers

2017ACM/ICPC亞洲區瀋陽-重現賽(感謝東北大學)

Little Boxes Problem Description Little boxes on the hillside. Little boxes made of ticky-tacky. Little boxes. Little boxes. Little boxes all

HDU-6223 Infinite Fraction Path(2017ACM/ICPC亞洲區瀋陽

思路:BFS+剪枝。對於每一層,找其最大值mm,對於小於mm的點和找的可能為同一個點進行剪枝。 Code: #include<iostream> #include<cstd

【HDOJ6229】Wandering Robots,set)

聯通 tin queue 開放 答案 轉移 first gcd 格子 題意:給定一個n*n的地圖,上面有k個障礙點不能走,有一個機器人從(0,0)出發,每次等概率的不動或者往上下左右沒有障礙的地方走動,問走無限步後停在圖的右下部的概率 n<=1e4,k<=1e3

HDU 5512 Pagodas(2015ACM/ICPC亞洲區瀋陽-重現賽(感謝東北大學))

Pagodas Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 3502 &nb

HDU 5950 - Recursive sequence - [矩陣快速冪加速遞推][2016ACM/ICPC亞洲區瀋陽 Problem C]

題目連結:http://acm.hdu.edu.cn/showproblem.php?pid=5950 Farmer John likes to play mathematics games with his N cows. Recently, they are attracted by recursive

2016ACM/ICPC亞洲區瀋陽 - A/B/C/E/G/H/I - (Undone)

連結:傳送門 A - Thickest Burger - [簽到水題] ACM ICPC is launching a thick burger. The thickness (or the height) of a piece of club steak is A (1 ≤ A ≤ 100). Th

HDU 5954 - Do not pour out - [積分+二分][2016ACM/ICPC亞洲區瀋陽 Problem G]

題目連結:http://acm.hdu.edu.cn/showproblem.php?pid=5954 Problem DescriptionYou have got a cylindrical cup. Its bottom diameter is 2 units and its height is 2

2015ACM/ICPC亞洲區瀋陽-——Pagodas(簡單博弈)

nn pagodas were standing erect in Hong Jue Si between the Niushou Mountain and the Yuntai Mountain, labelled from 11 to nn. However, only

2015ACM/ICPC亞洲區瀋陽---重現賽感想

今天打的差極了,,就A了兩個題,,今早九點開始,還真是有點困困的、、今天來的還有點晚。 先看的BD題,兩題並行,然後先敲的B,未果,D替代紙上完成。然後敲了D題,,A了之後就在做B和M,我先做的M,果然存圖沒想到,,然後就亂交了一發,,想象的T,結果RE了,,,遂放棄。

2015ACM/ICPC亞洲區瀋陽---題解

思路:就暴力匹配就好了,然後加一個剪枝,如果這個字串是某個字串的子串的話,就不用檢查他了就是個思維,還用了KMP,,其實不用也可以,用strstr()過的時間更短。。 程式碼: #inclu

2016ACM/ICPC亞洲區瀋陽 Counting Cliques HDU

題意:給你n個點,m條雙向邊,和一個整數s,要你求出大小等於s的完全子圖的個數(完全子圖:圖中的任一點都和其他所有點相連)。 演算法:dfs 思路: 將點逐個放進一個集合,如果該點與集合中的任一點

2016ACM/ICPC亞洲區瀋陽

題意:有序列F(n)=F(n-1)+2*F(n-2)+i^4;題目輸入N,F(1),F(2)讓輸出F(N)。N,F(1),F(2) < 2^31 解析:一看就是矩陣快速冪的題,推出以下轉移矩陣即可: 程式碼(9ms): #include <bits/

【解題報告】2015ACM/ICPC亞洲區瀋陽

題目連結 B. Bazinga(HDU5510) 思路 設第i個字串儲存在ss[i][]中。本題最直觀最樸素的做法是列舉兩個字串ss[i]和ss[j] (i+1≤j),再用KMP演算法匹配這兩個字串。首先從大到小列舉j,若對某個ss[j]存在某個s

hdu5512 Pagodas(2015ACM/ICPC亞洲區瀋陽-重現賽(感謝東北大學) )

n pagodas were standing erect in Hong Jue Si between the Niushou Mountain and the Yuntai Mountain, labelled from 1 to n. However, only two of them (labe

HDU 5950 Recursive sequence(構造矩陣+矩陣乘法)——2016ACM/ICPC亞洲區瀋陽(重現賽)

傳送門 Recursive sequenceTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 98  

2015ACM/ICPC亞洲區瀋陽 HDU

Ladies and gentlemen, please sit up straight.Don't tilt your head. I'm serious. For n given strings S1,S2,⋯,Sn, labelled from 1 to n, you should find

2017ACM/ICPC亞洲區沈陽 C Hdu-6219 Empty Convex Polygons 計算幾何 最大空凸包

sort get 沈陽 for mes c++ 幾何 targe oid 題面 題意:給你一堆點,求一個最大面積的空凸包,裏面沒有點. 題解:紅書板子,照抄完事,因為題目給的都是整點,所以最後答案一定是.5或者.0結尾,不用對答案多做處理 1 #inc