Advertisement
iletavcioski

kasl

Mar 29th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.20 KB | None | 0 0
  1. /*
  2. ID:ksmdjt1
  3. LANG:C++
  4. PROG:castle
  5. */
  6. #include <iostream>
  7. using namespace std;
  8. int visi[101][101];
  9. int brojac;
  10.  int mat[101][101];
  11.  int n,m;
  12. void dfs(int x,int y)
  13. {
  14.     if(visi[x][y])
  15.     return;
  16.     visi[x][y]=brojac;
  17.     if(y>0){
  18.     if((mat[x][y]&1)==0)
  19.     {
  20.         dfs(x,y-1);
  21.     }
  22.      }
  23.      if(y<(m-1))
  24.      {
  25.          if((mat[x][y]&4)==0){
  26.             dfs(x,y+1);
  27.          }
  28.      }
  29.      if(x>0){
  30.     if((mat[x][y]&2)==0){
  31.         dfs(x-1,y);
  32.     }
  33.      }
  34.      if(x<(n-1))
  35.      {
  36.          if((mat[x][y]&8)==0){
  37.             dfs(x+1,y);
  38.          }
  39.      }
  40.  
  41. }
  42. int main()
  43. {
  44. //ifstream fin("castle.in");
  45. //ofstream fout("castle.out");
  46.    cin>>m>>n;
  47.    for(int i=0;i<n;i++)
  48.    {
  49.        for(int j=0;j<m;j++)
  50.         cin>>mat[i][j],visi[i][j]=0;
  51.    }
  52.    brojac=0;
  53.    for(int i=0;i<n;i++)
  54.    {
  55.        for(int j=0;j<m;j++)
  56.        {
  57.            if(!visi[i][j])
  58.            {
  59.                brojac++;
  60.                dfs(i,j);
  61.            }
  62.        }
  63.    }
  64.    cout<<brojac<<endl;
  65.    int v[3003];
  66.    for(int i=0;i<3003;i++)
  67.     v[i]=0;
  68.    for(int i=0;i<n;i++)
  69.    {
  70.        for(int j=0;j<m;j++)
  71.        {
  72.            v[visi[i][j]]++;
  73.        }
  74.    }
  75.    int maxi=0;
  76.    for(int i=1;i<=brojac;i++)
  77.     maxi=max(maxi,v[i]);
  78.    cout<<maxi<<endl;
  79.    int maxxi=0;
  80.    int x1=-1;
  81.    int y1=-1;
  82.    char s;
  83.    for(int j=0;j<m;j++)
  84.    {
  85.        for(int i=n-1;i>=0;i--)
  86.        {
  87.  if((mat[i][j]&2)&&i>0)
  88.            {
  89.                if(visi[i][j]!=visi[i-1][j]){
  90.                if(maxxi<v[visi[i][j]]+v[visi[i-1][j]])
  91.                {
  92.                    maxxi=v[visi[i][j]]+v[visi[i-1][j]];
  93.                    x1=i+1;
  94.                    y1=j+1;
  95.                    s='N';
  96.                }
  97.                }
  98.            }
  99.            if((mat[i][j]&4)&&j<m-1)
  100.            {
  101.                if(visi[i][j]!=visi[i][j+1]){
  102.                if(maxxi<v[visi[i][j]]+v[visi[i][j+1]])
  103.                {
  104.                    maxxi=v[visi[i][j]]+v[visi[i][j+1]];
  105.                    x1=i+1;
  106.                    y1=j+1;
  107.                    s='E';
  108.                }
  109.                }
  110.            }
  111.          
  112.        }
  113.    }
  114.    cout<<maxxi<<endl;
  115.    cout<<x1<<" "<<y1<<" "<<s<<endl;
  116.  
  117.     return 0;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement