velimir

oFci

Feb 13th, 2014
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. //ofci == ovci;
  4. using namespace std;
  5. int x, y, ofci=0, volci=0;
  6. char mat[251][251];
  7. void BFS(int a, int b)
  8. {
  9. queue<int> redx, redy;
  10. redx.push(a);
  11. redy.push(b);
  12. while(!redx.empty())
  13. {
  14. int m = redx.front();
  15. int n = redy.front();
  16. redx.pop();
  17. redy.pop();
  18. if(mat[m][n]=='o')ofci++;
  19. if(mat[m][n]=='v')volci++;
  20. mat[m][n] = '#';
  21. if(m+1<x and mat[m+1][n]!='#') { redx.push(m+1); redy.push(n); }
  22. if(m-1>=0 and mat[m-1][n]!='#') { redx.push(m-1); redy.push(n); }
  23. if(n+1<y and mat[m][n+1]!='#') { redx.push(m); redy.push(n+1); }
  24. if(n-1>=0 and mat[m][n-1]!='#') { redx.push(m); redy.push(n-1); }
  25. }
  26. }
  27. int main()
  28. {
  29. int i, j, n, finalOfci = 0, finalVolci = 0;
  30. cin >> x >> y;
  31. for(i=0; i < x; i++)
  32. for(j=0; j < y; j++)
  33. cin >> mat[i][j];
  34. for(i=0; i < x; i++)
  35. for(j=0; j < y; j++)
  36. {
  37. if(mat[i][j] != '#')BFS(i, j);
  38. if(ofci>volci)finalOfci+=ofci;
  39. else finalVolci+=volci;
  40. ofci = 0;
  41. volci = 0;
  42. }
  43. cout << finalOfci << " " << finalVolci;
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment