Advertisement
abinash_hstu

SRM 676 Med

Dec 18th, 2015
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. struct BoardEscapeDiv2
  2. {
  3.     vector <string> m;
  4.     int check(pii n,int r,int c)
  5.     {
  6.         int o=0,e=0,cc=0;
  7.         FOR(i,0,3)
  8.         {
  9.             int nx=n.x+dx[i];
  10.             int ny=n.y+dy[i];
  11.             if(nx>=0&&nx<r&&ny>=0&&ny<c)
  12.             {
  13.                 if(m[nx][ny]=='E')e++;
  14.                 if(m[nx][ny]=='#')o++;
  15.                 cc++;
  16.             }
  17.         }
  18.         if(o==cc)return 100;
  19.         if(e>0)return e;
  20.         return -1;
  21.     }
  22.     string findWinner(vector <string> s, int k)
  23.     {
  24.         string ret;
  25.         m=s;
  26.         pii T;
  27.         int r=(int)s.size();
  28.         int c=(int)s[0].size();
  29.         FOR(i,0,r-1)
  30.             FOR(j,0,c-1)
  31.                 if(s[i][j]=='T')
  32.                     T=mp(i,j);
  33.         if(check(T,r,c)==100)ret="Bob";
  34.         else if(check(T,r,c)>0)ret="Alice";
  35.         else if(k==1)ret="Alice";
  36.         else
  37.         {
  38.             bool aa=false;
  39.             FOR(i,0,3)
  40.             {
  41.                 int nx=T.x+dx[i];
  42.                 int ny=T.y+dy[i];
  43.                 if(nx>=0&&nx<r&&ny>=0&&ny<c&&s[nx][ny]=='.')
  44.                     if(check(mp(nx,ny),r,c)==-1)
  45.                         aa=true;
  46.  
  47.             }
  48.             if(k%2==0)ret="Bob";
  49.             else ret="Alice";
  50.             if(!aa)ret="Bob";
  51.         }
  52.         return ret;
  53.     }
  54. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement