Advertisement
theo830

zvirus 2017 2018

Apr 27th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #include<iostream>
  2. #include<algorithm>
  3. using namespace std;
  4. # define MAX 1005
  5. int v[MAX][MAX];
  6. int u=0;
  7. int x,y;
  8. void near(int a,int b){
  9. if(v[a-1][b] == 1 && a > 0){
  10. v[a-1][b] = 0;
  11. u--;
  12. near(a-1,b);
  13. }
  14. if(v[a+1][b] == 1){
  15. v[a+1][b] = 0;
  16. u--;
  17. near(a+1,b);
  18. }
  19. if(v[a][b-1] == 1 && b > 0){
  20. v[a][b-1] = 0;
  21. u--;
  22. near(a,b-1);
  23. }
  24. if(v[a][b+1] == 1){
  25. v[a][b+1] = 0;
  26. u--;
  27. near(a,b+1);
  28. }
  29. }
  30. int main(){
  31. cin>>x>>y;
  32. int z;
  33. cin>>z;
  34. for(int i=0;i<x;i++){
  35. for(int j=0;j<y;j++){
  36. cin>>v[i][j];
  37. if(v[i][j] == 1){
  38. u++;
  39. }
  40. }
  41. }
  42. for(int y=0;y<z;y++){
  43. int a,b;
  44. cin>>a>>b;
  45. if(v[a-1][b-1] == 0){
  46. cout<<u<<endl;
  47. }
  48. else if(v[a-1][b-1] == 1){
  49. v[a-1][b-1] = 0;
  50. u--;
  51. near(a-1,b-1);
  52. cout<<u<<endl;
  53. }
  54. }
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement