Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include <fstream>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <math.h>
  7. #include <cmath>
  8. #include <string>
  9. #include <set>
  10. #include <deque>
  11. #include <cctype>
  12. #include <iomanip>
  13. #include <stdlib.h>
  14. #include <queue>
  15.  
  16. using namespace std;
  17.  
  18. enum Color
  19. {
  20. WHITE,
  21. BLACK
  22. };
  23.  
  24. void dfs(int x, int y, vector <vector<char>>& field, vector <vector<Color>>& colors)
  25. {
  26. colors[x][y] = BLACK;
  27. if (field[x + 1][y] == '#' && colors[x + 1][y] == WHITE)
  28. {
  29. dfs(x + 1, y, field, colors);
  30. }
  31. if (field[x - 1][y] == '#' && colors[x - 1][y] == WHITE)
  32. {
  33. dfs(x - 1, y, field, colors);
  34. }
  35. if (field[x][y + 1] == '#' && colors[x][y + 1] == WHITE)
  36. {
  37. dfs(x, y + 1, field, colors);
  38. }
  39. if (field[x][y - 1] == '#' && colors[x][y - 1] == WHITE)
  40. {
  41. dfs(x, y - 1, field, colors);
  42. }
  43. }
  44.  
  45. int main()
  46.  
  47. {
  48.  
  49. ifstream in("input.txt");
  50. ofstream out("output.txt");
  51. int n, ans = -10000000;
  52. in >> n;
  53. vector <vector <char>> field (100 + 2, vector <char> (100 + 2, '@'));
  54. vector <vector <Color>> colors (100 + 2, vector <Color> (100 + 2, WHITE));
  55. for (int i = 1; i <= 100; i++)
  56. {
  57. for (int j = 1; j <= 100; j++)
  58. {
  59. field[i][j] = '.';
  60. }
  61. }
  62. for (int i = 1; i <= n; i++)
  63. {
  64. int xS, yS, xE, yE;
  65. in >> xS >> yS >> xE >> yE;
  66. for (int j = xS; j <= xE; j++)
  67. {
  68. for (int k = yS; k <= yE; k++)
  69. {
  70. field[j][k] = '#';
  71. }
  72. }
  73. }
  74. for (int i = 1; i <= 100; i++)
  75. {
  76. for (int j = 1; j <= 100; j++)
  77. {
  78. if (field[i][j] == '#' && colors[i][j] == WHITE)
  79. {
  80. dfs(i, j, field, colors);
  81. }
  82. }
  83. }
  84. out << ans;
  85. out.close();
  86. in.close();
  87. return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement