"HDOJ6229" wandering Robots (Markov chain, set)

Source: Internet
Author: User
Tags gcd

Test instructions: Given a n*n map, above the K barrier point can not go, there is a robot from (0,0), each time such as the probability of the fixed or to the upper and lower left without obstacles to move around, asked to walk infinite steps after the probability of stopping in the right lower part of the graph

N<=1e4,k<=1e3

Idea: It is said to find the law

Proof from 78494788

Random walk model of Markov chain

  • The state transfer matrix can be established, and N * N points are numbered 0 ~[(n-1) * n + n–1] set to Max for n * n
    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) is the probability of the point of the I time
    π (n + 1) =π (n) * P
    When Time is infinite π (n + 1)->π
    can be calculated by π* P =π
    Verify that the guessed results are correct
    *******************************************************
    Finding the answers to the rules remains to be proved
    Now we can think of the whole closed-systems. Each lattice has the probability of a robot appearing as a weight value over a long time line is an entropy increase
    Process (think of cellular automata), if you want to simulate the process of probability diffusion, the update of the lattice's weights is a weighted value of the lattice he can reach.
    And the process of his own weight-value iteration, the process can be found that the weights of his neighboring lattices are constantly assimilated, and therefore, after infinity
    (0, 0) and the weight of the lattice around him are not the dominant, while the more open lattice is more dominant (can be understood according to the iterative formula)

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

    Considering the effect of each obstacle point on the answer, finding the rule is only related to the location of the obstacle point and the surrounding unicom situation.

    Check if the grid is not a barrier can use set

    1#include <cstdio>2#include <cstring>3#include <string>4#include <cmath>5#include <iostream>6#include <algorithm>7#include <map>8#include <Set>9#include <queue>Ten#include <vector> One using namespacestd; AtypedefLong Longll; -typedef unsignedint UINT; -typedef unsignedLong Longull; thetypedef pair<int,int>PII; -typedef vector<int>VI; - #defineFi first - #defineSe Second + #defineMP Make_pair - #defineN 11000 + #defineM 210 A #defineMOD 1e9+7 at #defineEPS 1e-8 - #definePi ACOs (-1) - intdx[]={0,-1,1,0,0},dy[]={0,0,0,-1,1}; - Set<int>St; -  -  in intRead () - {  to    intv=0, f=1; +    CharC=GetChar (); -     while(c< -|| $&LT;C) {if(c=='-') f=-1; C=GetChar ();} the     while( -<=c&&c<= $) v= (v<<3) +v+v+c- -, c=GetChar (); *    returnv*F; $ }Panax Notoginseng  - intgcdintXinty) the { +     if(y==0)returnx; A     returnGCD (y,x%y); the } +  - intMain () $ { $     //freopen ("hdoj6229.in", "R", stdin); -     //freopen ("Hdoj6299.out", "w", stdout); -     intCAs; thescanf"%d",&CAs); -      for(intv=1; v<=cas;v++)Wuyi     { the st.clear (); -         intn,m; Wuscanf"%d%d",&n,&m); -          for(intI=1; i<=m;i++) About         { $             intx, y; -scanf"%d%d",&x,&y); -St.insert (x*n+y); -         } A         ints1=n*n*5-n*4; +         ints2=n* (n+1)/2*5-2*n-2; the         Set<int>::iterator t=St.begin (); -          while(t!=st.end ()) $         { the             ints=*T; the             intx=s/N; the             inty=s%N; the              for(intI=1; i<=4; i++) -             { in                 inttx=x+Dx[i]; the                 intty=y+Dy[i]; the                 if(tx<0|| tx>=n| | ty<0|| ty>=n| | St.count (Tx*n+ty))Continue; Abouts1--; the                 if(tx+ty>=n-1) s2--; the             } the              +             if(x+y>=n-1) -             { thes2-=5;Bayi                 if(x==0|| x==n-1) s2++; the                 if(y==0|| y==n-1) s2++; the             } -              -s1-=5; the             if(x==0|| x==n-1) s1++; the             if(y==0|| y==n-1) s1++; thet++; the         } -          the         intk=gcd (S1,S2); theprintf"Case #%d:%d/%d\n", v,s2/k,s1/k); the     }    94     return 0; the } the      

"HDOJ6229" wandering Robots (Markov chain, set)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.