Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int main()
- {
- ifstream fin("rect.in");
- ofstream fout("rect.out");
- long long Xm, Ym, N;
- fin >> Xm >> Ym >> N;
- vector<pair<long long, long long>> Start;
- vector<pair<long long, long long>> End;
- for (size_t i = 0; i < N; i++)
- {
- long long x1, x2, y1, y2;
- fin >> x1 >> y1 >> x2 >> y2;
- long long tmp1, tmp2;
- /*if (y1 == 0 && x1 == 0)
- {
- tmp1 = ceil((double)x1 * Ym / y2);
- tmp2 = Xm + Ym - (Xm * y1) / x2;
- }
- else if (y1 == 0)
- {
- tmp1 = ceil((double)x1 * Ym / y2);
- tmp2 = Xm + Ym - (Xm * y1) / x2;
- }
- else if (x1 == 0)
- {
- tmp1 = ceil((double)x1 * Ym / y2);
- tmp2 = (double)x2 * Ym / y1;
- }
- else
- {
- tmp1 = ceil((double)x1 * Ym / y2);
- tmp2 = (double)x2* Ym / y1;
- }
- if (tmp1 > Xm)
- {
- tmp1 = ceil((double)Xm + Ym - (double)Xm * y2 / x1);
- }
- if (tmp2 > Xm)
- {
- tmp2 = Xm + Ym -(Xm*y1)/x2;
- }*/
- /*tmp1 = ceil((double)x1 * Ym / y2);
- tmp2 = (double)x2 * Ym / y1;
- if (y1 == 0)
- tmp2 = (double)Xm + Ym - (double)(Xm * y1) / x2;
- if(tmp1>Xm)
- tmp1 = ceil((double)Xm + Ym - (double)Xm * y2 / x1);
- if(tmp2>Xm)
- tmp2 = (double)Xm + Ym - (double)(Xm * y1) / x2;*/
- if (y2 != 0) {
- tmp1 = ceil((long double)x1 * Ym / y2);
- }
- if ((tmp1 > Xm) || (y2 == 0)) {
- tmp1 = ceil((long double)Xm + Ym - (long double)Xm * y2 / x1);
- }
- if (y0 != 0) {
- tmp2 = (long double)x2 * Ym / y1;
- }
- if ((tmp2 > Xm) || (y1 == 0)) {
- tmp2 = (long double)Xm + Ym - (long double)Xm * y1 / x2;
- }
- Start.push_back({ tmp1, Ym });
- End.push_back({ tmp2, Ym });
- }
- sort(Start.begin(), Start.end());
- sort(End.begin(), End.end());
- /*for (size_t i = 0; i < Start.size(); i++)
- {
- cout << Start[i].first << " " << Start[i].second << "\t" << End[i].first << " " << End[i].second << endl;
- }*/
- long long count = 0, count1 = 0, count2 = 0, x = 0;
- size_t j = Start.size()*2;
- for (size_t i = 0; i < j; i++)
- {
- if (Start.empty() || End.empty())
- break;
- long long tmp1;
- if (Start.front().first <= End.front().first)
- {
- ++count1;
- tmp1 = Start.front().first;
- Start.erase(Start.begin());
- }
- else
- {
- ++count2;
- End.erase(End.begin());
- }
- if (count < count1 - count2)
- {
- count = count1 - count2;
- x = tmp1;
- }
- }
- if (x > Xm)
- {
- x = Ym + Xm - x;
- fout << count << " " << Xm << " " << x << endl;
- }
- else
- {
- fout << count << " " << x << " " << Ym << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement