Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <fstream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. ifstream fin("maria.in");
  7. ofstream fout("maria.out");
  8.  
  9. int n, m, p, q;
  10. int k;
  11. int a[1001][1001];
  12. int sum[1001][1001];
  13.  
  14. int cautaLocuri(int p, int q)
  15. {
  16. int locuri = 0;
  17. int s;
  18. int x1, y1, x2, y2;
  19. for (int i = 1; i <= n - p + 1; ++i)
  20. {
  21. for (int j = 1; j <= m - q + 1; ++j)
  22. {
  23. x1 = i;
  24. y1 = j;
  25. x2 = i + p - 1;
  26. y2 = j + q - 1;
  27. s = sum[x2][y2] - sum[x2][y1 - 1] - sum[x1 - 1][y2] + sum[x1 - 1][y1 - 1];
  28. if (s == 0)
  29. ++locuri;
  30. }
  31. }
  32. return locuri;
  33. }
  34.  
  35. int main()
  36. {
  37. fin >> n >> m >> p >> q;
  38. fin >> k;
  39. int x, y;
  40. for (int i = 1; i <= k; ++i)
  41. {
  42. fin >> x >> y;
  43. a[x][y] = 1;
  44. }
  45. for (int i = 1; i <= n; ++i)
  46. {
  47. for (int j = 1; j <= m; ++j)
  48. {
  49. sum[i][j] = a[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
  50. }
  51. }
  52. int cnt = 0;
  53. cnt += cautaLocuri(p, q);
  54. cnt += cautaLocuri(q, p);
  55. fout << cnt;
  56.  
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement