Advertisement
Korotkodul

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

Jan 8th, 2022
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 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. ll ans=0;
  65.  
  66. //scan y
  67. ll scy(int xjn){ //x join
  68. ll join = 0;
  69. int bly = 1;
  70. int y1, y2;
  71. y1 = ally[0].y1.y;
  72. for (int i = 1; i < ally.size();++i){
  73. if (ally[i].tp == 0){
  74. bly++;
  75. if (bly == 1){
  76. y1 = ally[i].y1.y;
  77. }
  78. }
  79. else{
  80. bly--;
  81. if (bly == 0){
  82. y2 = ally[i].y2.y;
  83. }
  84. }
  85. if (bly == 0){
  86. ans +=
  87. }
  88. }
  89. }
  90.  
  91. int main()
  92. {
  93. ios::sync_with_stdio(0);
  94. cin.tie(0);
  95. cout.tie(0);
  96. int n; cin>>n;
  97. for (int i=0;i<n;++i){
  98. int x1, y1, x2, y2;
  99. cin>>x1>>y1>>x2>>y2;
  100. hpnx xl, xr;
  101. hpny yl, yr;
  102. yl = {y1, 0};
  103. yr = {y2, 1};
  104. xl = {x1, 0, yl, yr};
  105. xr = {x2, 1, yl, yr};
  106. allx.push_back(xl);
  107. allx.push_back(xr);
  108. }
  109. sort(allx.begin(), allx.end(), cmpx);
  110. int blx = 1;
  111. int x1, x2;
  112. x1 = allx[0].x;
  113. ally.push_back(allx[0].y1);
  114. ally.push_back(allx[0].y2);
  115. for (int i = 1; i < n * 2; ++i){
  116. //shx(allx[i]);
  117. x2 = allx[i].x;
  118. if (allx[i].tp == 1){
  119. blx--;
  120. int id1, id2;
  121. for (int j = 0; j < ally.size();++j){
  122. if (ally[j].y == allx[i].y1.y && ally[j].tp == 0){
  123. id1 = j;
  124. }
  125. else if (ally[j].y == allx[i].y2.y && ally[j].tp == 1){
  126. id2 = j;
  127. }
  128. }
  129. ally.erase(ally.begin() + id1);
  130. id2--;
  131. ally.erase(ally.begin() + id2);
  132. }
  133.  
  134. scy(x2 - x1);
  135.  
  136.  
  137. if (allx[i].tp == 0){
  138. blx++;
  139. ally.push_back(allx[i].y1);
  140. ally.push_back(allx[i].y2);
  141. sort(ally.begin(), ally.end(), cmpy);
  142. }
  143.  
  144. x1 = x2;
  145. }
  146. }
  147.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement