Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. vector<int> parent;
  4. int find(int x)
  5. {
  6.     if (parent[x]==x)   return x;
  7.     return parent[x]=find(parent[x]);
  8. }
  9.  
  10. void join(int x, int y)
  11. {
  12.     parent[x]=find(y);
  13. }
  14.  
  15. int main() {
  16.     int r,c;
  17.     cin>>r>>c;
  18.     parent.resize(r*c);
  19.     vector<string> map(r);
  20.     for (int i = 0; i < r*c; ++i)
  21.     {
  22.         parent[i]=i;
  23.     }
  24.     for (int i = 0; i < r; ++i)
  25.     {
  26.         cin>>map[i];
  27.     }
  28.     for (int i = 0; i < r; ++i)
  29.     {
  30.         for (int j = 0; j < c; ++j)
  31.         {
  32.             if (j<c-1)
  33.             {
  34.                 if (map[i][j]==map[i][j+1])
  35.                 {
  36.                     join(i*c+j, i*c+j+1);  
  37.                    
  38.                 }
  39.             }
  40.             if (i<r-1)
  41.             {
  42.                 if (map[i][j]==map[i+1][j])
  43.                 {
  44.                     join(i*c+j, (i+1)*c+j);
  45.                 }
  46.             }  
  47.         }
  48.     }
  49.     int n;
  50.     cin>>n;
  51.     int r1,c1,r2,c2;
  52.     for (int i = 0; i < n; ++i)
  53.     {
  54.         cin>>r1>>c1>>r2>>c2;
  55.         r1--;
  56.         c1--;
  57.         r2--;
  58.         c2--;
  59.         if (find(r1*c+c1)==find(r2*c+c2))
  60.         {
  61.             if (map[r1][c1]=='0')
  62.             {
  63.                 cout<<"binary"<<endl;
  64.             }
  65.             else cout<<"decimal"<<endl;
  66.         }
  67.         else cout<<"neither"<<"\n";
  68.     }
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement