Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <deque>
  4. #include <algorithm>
  5.  
  6. int main()
  7. {
  8. std::ifstream input("rect.in");
  9. std::ofstream output("rect.out");
  10.  
  11.  
  12. double Y, X;
  13. long N;
  14. input>> X >> Y >> N;
  15.  
  16. std::deque < std::pair<double, double>> begining;
  17. std::deque < std::pair<double, double>> ending;
  18. std::deque<double> begin_;
  19. std::deque<double> end_;
  20.  
  21. double x1, x2, y1, y2;
  22.  
  23. int i = 0;
  24. while (i < N) {
  25. input>> x1 >> y1 >> x2 >> y2;
  26. begining.push_back(std::make_pair(x1, y2));
  27. ending.push_back(std::make_pair(x2, y1));
  28. i++;
  29. }
  30.  
  31. i = 0;
  32. while (i < N) {
  33. if ((Y * begining[i].first / begining[i].second) < X)
  34. begin_.push_back(ceil(Y * begining[i].first / begining[i].second));
  35. else
  36. {
  37. begin_.push_back(ceil(Y - X * begining[i].second / begining[i].first + X));
  38. }
  39. if ((Y * ending[i].first / ending[i].second) < X)
  40. end_.push_back(floor(Y * ending[i].first / ending[i].second));
  41. else
  42. {
  43. end_.push_back(floor(Y - X * ending[i].second / ending[i].first + X));
  44. }
  45. i++;
  46. }
  47.  
  48. sort(begin_.begin(), begin_.end());
  49. sort(end_.begin(), end_.end());
  50.  
  51. int b = 0,max = 0,rect = 1;
  52. int x = 0;
  53.  
  54. i = 0;
  55. while (i < N) {
  56. if (begin_[i] <= end_[b])
  57. rect++;
  58. else
  59. {
  60. rect--;
  61. b++;
  62. i--;
  63. }
  64. if (rect > max)
  65. {
  66. max = rect;
  67. x = begin_[i];
  68. }
  69. i++;
  70. }
  71.  
  72. if (x < X)
  73. output<< max-1 << " " <<x << " " <<Y;
  74. else
  75. output<< max-1 << " " <<X << " " <<X +Y -x;
  76. input.close();
  77. output.close();
  78. return 0;
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement