Advertisement
Josif_tepe

Untitled

Nov 7th, 2021
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int a,b;
  8.     cin>>a>>b;
  9.     int x;
  10.     cin>>x;
  11.     char mat[a][b];
  12.     int pos[a][b];
  13.     queue<int>Q;
  14.     bool visited[a][b];
  15.     for(int i=0;i<a;i++)
  16.     {
  17.         for(int j=0;j<b;j++)
  18.         {
  19.             cin>>mat[i][j];
  20.             pos[i][j]=0;
  21.             visited[i][j]=false;
  22.         }
  23.     }
  24.     for(int i=0;i<a;i++)
  25.     {
  26.         for(int j=0;j<b;j++)
  27.         {
  28.             if(mat[i][j]=='C')
  29.             {
  30.                 Q.push(i);
  31.                 Q.push(j);
  32.                 Q.push(x);
  33.             for(int k=0;k<a;k++)
  34.             {
  35.                 for(int l=0;l<b;l++)
  36.                 {
  37.                     visited[k][l]=false;
  38.                 }
  39.             }
  40.                 visited[i][j] = true;
  41.                 while(!Q.empty())
  42.                 {
  43.                     int ci=Q.front();
  44.                     Q.pop();
  45.                     int cj=Q.front();
  46.                     Q.pop();
  47.                     int n=Q.front();
  48.                     Q.pop();
  49.                     if(mat[ci][cj]=='.')
  50.                     {
  51.                         pos[ci][cj]++;
  52.                     }
  53.                     if(n - 1 >= 0) {
  54.                     if(cj+1<b && mat[ci][cj+1]!='#' && visited[ci][cj+1]==false)
  55.                     {
  56.                         Q.push(ci);
  57.                         Q.push(cj+1);
  58.                         Q.push(n-1);
  59.                         visited[ci][cj+1]=true;
  60.                     }
  61.                     if(cj-1>=0 && mat[ci][cj-1]!='#' && visited[ci][cj-1]==false)
  62.                     {
  63.                         Q.push(ci);
  64.                         Q.push(cj-1);
  65.                         Q.push(n-1);
  66.                         visited[ci][cj-1]=true;
  67.                     }
  68.                     if(ci+1<a && mat[ci+1][cj]!='#' && visited[ci+1][cj]==false)
  69.                     {
  70.                         Q.push(ci+1);
  71.                         Q.push(cj);
  72.                         Q.push(n-1);
  73.                         visited[ci+1][cj]=true;
  74.                     }
  75.                      if(ci-1>=0 && mat[ci-1][cj]!='#' && visited[ci-1][cj]==false)
  76.                     {
  77.                         Q.push(ci-1);
  78.                         Q.push(cj);
  79.                         Q.push(n-1);
  80.                         visited[ci-1][cj]=true;
  81.                     }
  82.                     }
  83.                 }
  84.                 while(!Q.empty())
  85.                 {
  86.                     Q.pop();
  87.                 }
  88.             }
  89.         }
  90.     }
  91.     int najgolem=-1;
  92.     for(int i=0;i<a;i++)
  93.     {
  94.         for(int j=0;j<b;j++)
  95.         {
  96.             if(najgolem<pos[i][j])
  97.             {
  98.                 najgolem=pos[i][j];
  99.             }
  100.         }
  101.     }
  102.     //cout<<najgolem;
  103.     for(int i=0;i<a;i++)
  104.     {
  105.         for(int j=0;j<b;j++)
  106.         {
  107.             if(pos[i][j]==najgolem)
  108.             {
  109.                 cout<<i+1<<" "<<j+1;
  110.                 return 0;
  111.             }
  112.         }
  113.     }
  114.     return 0;
  115. }
  116.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement