Advertisement
Korotkodul

ЗОШ объедини прямоугольники

Jan 8th, 2022 (edited)
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int,int>
  11. using namespace std;
  12. using ll = long long;
  13. using ld = long double;
  14. void cv(vector <int> &v){
  15. for (auto x: v) cout<<x<<' ';
  16. cout<<"\n";
  17. }
  18.  
  19. void cvl(vector <ll> &v){
  20. for (auto x: v) cout<<x<<' ';
  21. cout<<"\n";
  22. }
  23.  
  24.  
  25. void cvv(vector <vector <int> > &v){
  26. for (auto x: v) cv(x);
  27. cout<<"\n";
  28. }
  29.  
  30. struct hpny{
  31. int y, tp;
  32. };
  33.  
  34. struct hpnx{
  35. int x,tp; //0-открыл, 1 -закрыл
  36. hpny y1, y2;
  37. };
  38.  
  39. void shx(hpnx sm){
  40. cout<<"x = "<<sm.x<<"\n";
  41. cout<<"type = "<<sm.tp<<"\n";
  42. cout<<"\n";
  43. }
  44.  
  45. void shy(hpny sm){
  46. cout<<"y = "<<sm.y<<"\n";
  47. cout<<"type = "<<sm.tp<<"\n";
  48. cout<<"\n";
  49. }
  50.  
  51. vector <hpnx> allx;
  52.  
  53. vector <hpny> ally;//now
  54.  
  55.  
  56. bool cmpx(hpnx a, hpnx b){
  57. return a.x < b.x;
  58. }
  59.  
  60. bool cmpy(hpny a, hpny b){
  61. return a.y < b.y;
  62. }
  63.  
  64. int main()
  65. {
  66. ios::sync_with_stdio(0);
  67. cin.tie(0);
  68. cout.tie(0);
  69. int n; cin>>n;
  70. for (int i=0;i<n;++i){
  71. int x1, y1, x2, y2;
  72. cin>>x1>>y1>>x2>>y2;
  73. hpnx xl, xr;
  74. hpny yl, yr;
  75. yl = {y1, 0};
  76. yr = {y2, 1};
  77. xl = {x1, 0, yl, yr};
  78. xr = {x2, 1, yl, yr};
  79. allx.push_back(xl);
  80. allx.push_back(xr);
  81. }
  82. sort(allx.begin(), allx.end(), cmpx);
  83. int blx = 1;
  84. int x1, x2;
  85. x1 = allx[0].x;
  86. ally.push_back(allx[0].y1);
  87. ally.push_back(allx[0].y2);
  88. for (int i = 1; i < n * 2; ++i){
  89. //shx(allx[i]);
  90. if (allx[i].tp == 1){
  91. blx--;
  92. int id1, id2;
  93. for (int j = 0; j < ally.size();++j){
  94. if (ally[j].y == allx[i].y1.y && ally[j].tp == 0){
  95. id1 = j;
  96. }
  97. else if (ally[j].y == allx[i].y2.y && ally[j].tp == 1){
  98. id2 = j;
  99. }
  100. }
  101. ally.erase(ally.begin() + id1);
  102. id2--;
  103. ally.erase(ally.begin() + id2);
  104. }
  105. }
  106. }
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement