Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <deque>
- #include <algorithm>
- int main()
- {
- std::ifstream input("rect.in");
- std::ofstream output("rect.out");
- double Y, X;
- long N;
- input>> X >> Y >> N;
- std::deque < std::pair<double, double>> begining;
- std::deque < std::pair<double, double>> ending;
- std::deque<double> begin_;
- std::deque<double> end_;
- double x1, x2, y1, y2;
- int i = 0;
- while (i < N) {
- input>> x1 >> y1 >> x2 >> y2;
- begining.push_back(std::make_pair(x1, y2));
- ending.push_back(std::make_pair(x2, y1));
- i++;
- }
- i = 0;
- while (i < N) {
- if ((Y * begining[i].first / begining[i].second) < X)
- begin_.push_back(ceil(Y * begining[i].first / begining[i].second));
- else
- {
- begin_.push_back(ceil(Y - X * begining[i].second / begining[i].first + X));
- }
- if ((Y * ending[i].first / ending[i].second) < X)
- end_.push_back(floor(Y * ending[i].first / ending[i].second));
- else
- {
- end_.push_back(floor(Y - X * ending[i].second / ending[i].first + X));
- }
- i++;
- }
- sort(begin_.begin(), begin_.end());
- sort(end_.begin(), end_.end());
- int b = 0,max = 0,rect = 1;
- int x = 0;
- i = 0;
- while (i < N) {
- if (begin_[i] <= end_[b])
- rect++;
- else
- {
- rect--;
- b++;
- i--;
- }
- if (rect > max)
- {
- max = rect;
- x = begin_[i];
- }
- i++;
- }
- if (x < X)
- output<< max-1 << " " <<x << " " <<Y;
- else
- output<< max-1 << " " <<X << " " <<X +Y -x;
- input.close();
- output.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement