Advertisement
Josif_tepe

Untitled

Mar 24th, 2021
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n;
  8. int m;
  9.  
  10. cin>>n>>m;
  11. char matrica[n][m];
  12. queue<int>q;
  13. int volci=0;
  14. int ovci=0;
  15. for(int x=0; x<n; x++){
  16.     for(int x1=0; x1<m; x1++){
  17.         cin>>matrica[x][x1];
  18.     }
  19. }
  20. bool visited[n][m];
  21. for(int y=0; y<n; y++){
  22.     for(int y1=0; y1<m; y1++){
  23.         visited[y][y1]=false;
  24.     }
  25. }
  26. for(int u=0; u<n; u++){
  27.     for(int u1=0; u1<m; u1++){
  28.         if((matrica[u][u1]!='#')and(visited[u][u1]==false)){
  29.          q.push(u);
  30.          q.push(u1);
  31.          visited[u][u1]=true;
  32.          int obr=0;
  33.          int vbr=0;
  34.          while(!q.empty()){
  35.             int ci=q.front();
  36.             q.pop();
  37.             int cj=q.front();
  38.             q.pop();
  39.              if((ci+1<n)and(matrica[ci+1][cj]!='#')and(visited[ci+1][cj]!=true)){
  40.                              q.push(ci+1);
  41.                              q.push(cj);
  42.                              visited[ci+1][cj]=true;
  43.  
  44.                       }
  45.                       if((ci-1>=0)and(matrica[ci-1][cj]!='#')and(visited[ci-1][cj]!=true)){
  46.                              q.push(ci-1);
  47.                              q.push(cj);
  48.                              visited[ci-1][cj]=true;
  49.                          }
  50.                          if((cj+1<m)and(matrica[ci][cj+1]!='#')and(visited[ci][cj+1]!=true)){
  51.                              q.push(ci);
  52.                              q.push(cj+1);
  53.                              visited[ci][cj+1]=true;
  54.                      }
  55.                      if((cj-1>=0)and(matrica[ci][cj-1]!='#')and(visited[ci][cj-1]!=true)){
  56.                              q.push(ci);
  57.                              q.push(cj-1);
  58.                              visited[ci][cj-1]=true;
  59.              }
  60.              if(matrica[ci][cj]=='v'){
  61.              vbr+=1;
  62.              }
  63.              else if(matrica[ci][cj]=='o'){
  64.              obr+=1;
  65.              }
  66.              }
  67.              if(vbr>=obr){
  68.              volci+=vbr;
  69.  
  70.              }
  71.              else{
  72.              ovci+=obr;
  73.              }
  74.              }
  75.              }
  76.              }
  77.              cout<<ovci << " "<<volci;
  78.                  return 0;
  79.              }
  80. /*
  81.  3 3
  82.  vvv
  83.  ooo
  84.  ooo
  85.  */
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement