Advertisement
Ryuuk

test

Sep 22nd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int r,c;
  5. string ss;
  6. char mat[51][51];
  7. int go[2501][4];
  8. int dr[4] = {0,0,1,-1};
  9. int dc[4] = {-1,1,0,0};
  10.  
  11.  
  12. pair<int,int> next_(int x,int y, int i, int j, char previous)
  13. {
  14.   if(mat[x][y]!=previous)
  15.     return make_pair(x,y);
  16.   else
  17.   {
  18.     if(x+i>r || y+j>c)
  19.       return make_pair(-1,-1);
  20.     return next_(x+i,y+j,i,j,mat[i][j]);
  21.   }
  22. }
  23.  
  24.  
  25. void build()
  26. {
  27.   for(int i=0;i<r;i++)
  28.     for(int j=0;j<c;j++)
  29.       for(int k=0;k<4;k++)
  30.       {
  31.         pair<int,int> x = next_(i+dr[k],j+dc[k],dr[k],dc[k],mat[i][j]);
  32.         go[i*c+r][k] = (x.first==-1)?-1: x.first * r + x.second;
  33.       }
  34. }
  35.  
  36. void read_mat()
  37. {
  38.   for(int i=0;i<r;i++)
  39.     for(int j=0;j<c;j++)
  40.       cin>>mat[i][j];
  41. }
  42.  
  43. void solve()
  44. {
  45.  
  46. }
  47.  
  48. int main()
  49. {
  50.   while(cin>>r>>c)
  51.   {
  52.     read_mat();
  53.     build();
  54.     cin>>ss;
  55.     solve();
  56.   }
  57.   return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement