Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- //ofci == ovci;
- using namespace std;
- int x, y, ofci=0, volci=0;
- char mat[251][251];
- void BFS(int a, int b)
- {
- queue<int> redx, redy;
- redx.push(a);
- redy.push(b);
- while(!redx.empty())
- {
- int m = redx.front();
- int n = redy.front();
- redx.pop();
- redy.pop();
- if(mat[m][n]=='o')ofci++;
- if(mat[m][n]=='v')volci++;
- mat[m][n] = '#';
- if(m+1<x and mat[m+1][n]!='#') { redx.push(m+1); redy.push(n); }
- if(m-1>=0 and mat[m-1][n]!='#') { redx.push(m-1); redy.push(n); }
- if(n+1<y and mat[m][n+1]!='#') { redx.push(m); redy.push(n+1); }
- if(n-1>=0 and mat[m][n-1]!='#') { redx.push(m); redy.push(n-1); }
- }
- }
- int main()
- {
- int i, j, n, finalOfci = 0, finalVolci = 0;
- cin >> x >> y;
- for(i=0; i < x; i++)
- for(j=0; j < y; j++)
- cin >> mat[i][j];
- for(i=0; i < x; i++)
- for(j=0; j < y; j++)
- {
- if(mat[i][j] != '#')BFS(i, j);
- if(ofci>volci)finalOfci+=ofci;
- else finalVolci+=volci;
- ofci = 0;
- volci = 0;
- }
- cout << finalOfci << " " << finalVolci;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment