Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define in f
  4. #define out cout
  5.  
  6.  
  7. ifstream f ("a.in");
  8. ofstream g("tsunami.out");
  9.  
  10. queue<pair<int, int>> q;
  11. int viz[200][200];
  12. int n;
  13. int m;
  14. int M[200][200];
  15. int h;
  16. int node;
  17. int rez;
  18.  
  19.  
  20. bool check(int i, int j)
  21. {
  22. if(i < 1 || j < 1 || i > n || j > m)
  23. return false;
  24.  
  25. if(viz[i][j] == true)
  26. {
  27. return false;
  28. }
  29. else
  30. {
  31. if(M[i][j] > 0)
  32. {
  33. if(M[i][j] < h)
  34. return true;
  35. else return false;
  36. }
  37.  
  38. return true;
  39. }
  40. }
  41.  
  42. int main() {
  43.  
  44. in >> n;
  45. in >> m;
  46. in >> h;
  47.  
  48. for(int i = 1; i <= n; i++) {
  49. for(int j = 1; j <= m; j++) {
  50. in >> M[i][j];
  51. if(M[i][j] == 0) {
  52. q.push({i,j});
  53. viz[i][j]++;
  54. }
  55. }
  56. }
  57. while(q.empty() == false) {
  58. pair <int, int> node = q.front();
  59. q.pop();
  60. if((viz[node.first - 1][node.second] == 0) && (M[node.first - 1][node.second] < h)) {
  61. viz[node.first - 1][node.second]++;
  62. q.push({node.first - 1, node.second});
  63. check(node.first, node.second);
  64. }
  65. if((viz[node.first + 1][node.second] == 0) && (M[node.first + 1][node.second] < h)) {
  66. viz[node.first + 1][node.second]++;
  67. q.push({node.first + 1, node.second});
  68. check(node.first, node.second);
  69. }
  70. if((viz[node.first ][node.second - 1] == 0) && (M[node.first][node.second - 1] < h)) {
  71. viz[node.first][node.second - 1]++;
  72. q.push({node.first, node.second - 1});
  73. check(node.first, node.second);
  74. }
  75. if((viz[node.first][node.second + 1] == 0) && (M[node.first][node.second + 1] < h)) {
  76. viz[node.first][node.second + 1]++;
  77. q.push({node.first, node.second + 1});
  78. check(node.first, node.second);
  79. }
  80. }
  81.  
  82. for(int i = 1; i <= n; i++) {
  83. for(int j = 1; j <= m; j++) {
  84. if(viz[i][j] == 0) {
  85. rez++;
  86. }
  87. }
  88. }
  89. out << rez;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement