Guest User

Untitled

a guest
Jan 6th, 2012
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cassert>
  5. #include <cstring>
  6. using namespace std;
  7. typedef long double ld;
  8. ld m[1<<6][1<<6],h[1<<6][1<<6];
  9. int init[1<<3][1<<3];
  10. int dx[] = {-1,-1,0,1,1,1,0,-1};
  11. int dy[] = {0,1,1,1,0,-1,-1,-1};
  12. const int wh = 43;
  13. inline void mul(){
  14.     for(int i=0;i<64;++i) {
  15.         for(int j=0;j<64;++j){
  16.             h[i][j]=m[i][j]; m[i][j]=0;
  17.         }
  18.     }
  19.     for(int i=0;i<64;++i){
  20.         for(int j=0;j<64;++j) {
  21.             for(int k= 0;k<64;++k) {
  22.                 m[i][j]+=h[i][k]*h[k][j];
  23.             }
  24.         }
  25.         ld n=0;
  26.         for(int j=0;j<64;++j) {
  27.             n+=m[i][j];
  28.         }
  29.         for(int j=0;j<64;++j) {
  30.             m[i][j]/=n;
  31.         }
  32.     }
  33. }
  34. inline bool in_board(int x, int y) { return x < 8 && y < 8 && x>=0 && y>=0;}
  35.  
  36. int main(){
  37.     int x,y;
  38.     for(int i=0;i<8;++i) {
  39.         for(int j=0;j<8;++j) {
  40.             cin>>init[i][j];
  41.         }
  42.     }
  43.     for(int i=0;i<8;++i) {
  44.         for(int j=0;j<8;++j){
  45.             int n = 0;
  46.             for(int k=0;k<8;++k){
  47.                 if (in_board(x=i+dx[k],y=j+dy[k])) {
  48.                     n+=init[x][y];
  49.                 }
  50.             }
  51.             for(int k=0;k<8;++k){
  52.                 if (in_board(x=i+dx[k],y=j+dy[k])){
  53.                     m[i*8+j][x*8+y]=(ld)init[x][y] / n;
  54.                 }
  55.             }
  56.         }
  57.     }
  58.     for(long long a=1LL<<40; a; a>>=1){
  59.         mul();
  60.     }
  61.     for(int i=0;i<64;++i){
  62.         printf("%.12Lf ",m[wh][i]);
  63.         if (i%8==7) printf("\n");
  64.     }
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment