SuitNdtie

Mravojed PROG1074

Apr 4th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<cmath>
  3. using namespace std;
  4. bool debug = false;
  5. int main()
  6. {
  7.     int r,c;
  8.     int countall = 0;
  9.     scanf("%d %d",&r,&c);
  10.     char field[r+1][c+1];
  11.     bool visited[r+1][c+1];for(int i=0;i<=r;i++)for(int j=0;j<=c;j++)visited[i][j] = false;
  12.     for(int i=1;i<=r;i++){
  13.         for(int j=1;j<=c;j++){
  14.             scanf(" %c",&field[i][j]);
  15.             if(field[i][j] == 'x')countall++;
  16.         }
  17.     }
  18.     int ca = 0;
  19.     for(int i=1;i<=r;i++){
  20.         for(int j=1;j<= c;j++){
  21.             if(field[i][j] == 'x'){
  22.                 int ncI = i;
  23.                 int ncJ = j;
  24.                 while(field[ncI+1][ncJ+1] == 'x' && ncI+1 <= r && ncJ+1 <= c){
  25.                     int ti = i,tj = j;
  26.                     ncI++;
  27.                     ncJ++;
  28.                     while(field[ncI][tj] == 'x' && tj < ncJ)tj++;
  29.                     while(field[ti][ncJ] == 'x' && ti < ncI)ti++;
  30.                     if(tj != ncJ || ti != ncI){
  31.                         ncI--;
  32.                         ncJ--;
  33.                         break;
  34.                     }
  35.                 }
  36.                 if(debug)printf("Test (%d,%d) -> (%d,%d) = ",i,j,ncI,ncJ);
  37.                 int countsquare = 0;
  38.                 for(int ti = i ; ti <= ncI ; ti++){
  39.                     for(int tj = j ; tj <= ncJ ; tj++){
  40.                         if(!visited[ti][tj] && field[ti][tj] == 'x'){
  41.                             countsquare++;
  42.                             visited[ti][tj] = true;
  43.                             countall--;
  44.                         }
  45.                     }
  46.                 }
  47.                 if(debug)printf("sq : %d , ca : %d\n",countsquare,countall);
  48.                 int size = (int)sqrt((ncI - i + 1)*(ncJ - j + 1));
  49.                 if(countsquare == size*size){
  50.                     printf("%d %d %d\n",i,j,size);
  51.                     ca++;
  52.                     if(ca == 2)return 0;
  53.                 }
  54.                 else if(countall == 0){
  55.                     printf("%d %d %d\n",i,j,size);
  56.                     return 0;
  57.                 }
  58.             }
  59.         }
  60.     }
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment