Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. #include <fstream>
  2. #include <vector>
  3. #include <iostream>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. ifstream fin("rect.in");
  10. ofstream fout("rect.out");
  11. long long Xm, Ym, N;
  12. fin >> Xm >> Ym >> N;
  13. vector<pair<long long, long long>> Start;
  14. vector<pair<long long, long long>> End;
  15. for (size_t i = 0; i < N; i++)
  16. {
  17. long long x1, x2, y1, y2;
  18. fin >> x1 >> y1 >> x2 >> y2;
  19. long long tmp1, tmp2;
  20. /*if (y1 == 0 && x1 == 0)
  21. {
  22. tmp1 = ceil((double)x1 * Ym / y2);
  23. tmp2 = Xm + Ym - (Xm * y1) / x2;
  24. }
  25. else if (y1 == 0)
  26. {
  27. tmp1 = ceil((double)x1 * Ym / y2);
  28. tmp2 = Xm + Ym - (Xm * y1) / x2;
  29. }
  30. else if (x1 == 0)
  31. {
  32. tmp1 = ceil((double)x1 * Ym / y2);
  33. tmp2 = (double)x2 * Ym / y1;
  34. }
  35. else
  36. {
  37. tmp1 = ceil((double)x1 * Ym / y2);
  38. tmp2 = (double)x2* Ym / y1;
  39. }
  40.  
  41. if (tmp1 > Xm)
  42. {
  43. tmp1 = ceil((double)Xm + Ym - (double)Xm * y2 / x1);
  44. }
  45.  
  46. if (tmp2 > Xm)
  47. {
  48. tmp2 = Xm + Ym -(Xm*y1)/x2;
  49. }*/
  50.  
  51.  
  52. /*tmp1 = ceil((double)x1 * Ym / y2);
  53. tmp2 = (double)x2 * Ym / y1;
  54. if (y1 == 0)
  55. tmp2 = (double)Xm + Ym - (double)(Xm * y1) / x2;
  56. if(tmp1>Xm)
  57. tmp1 = ceil((double)Xm + Ym - (double)Xm * y2 / x1);
  58. if(tmp2>Xm)
  59. tmp2 = (double)Xm + Ym - (double)(Xm * y1) / x2;*/
  60.  
  61. if (y2 != 0) {
  62. tmp1 = ceil((long double)x1 * Ym / y2);
  63. }
  64. if ((tmp1 > Xm) || (y2 == 0)) {
  65. tmp1 = ceil((long double)Xm + Ym - (long double)Xm * y2 / x1);
  66. }
  67. if (y0 != 0) {
  68. tmp2 = (long double)x2 * Ym / y1;
  69. }
  70. if ((tmp2 > Xm) || (y1 == 0)) {
  71. tmp2 = (long double)Xm + Ym - (long double)Xm * y1 / x2;
  72. }
  73. Start.push_back({ tmp1, Ym });
  74. End.push_back({ tmp2, Ym });
  75. }
  76. sort(Start.begin(), Start.end());
  77. sort(End.begin(), End.end());
  78. /*for (size_t i = 0; i < Start.size(); i++)
  79. {
  80. cout << Start[i].first << " " << Start[i].second << "\t" << End[i].first << " " << End[i].second << endl;
  81. }*/
  82. long long count = 0, count1 = 0, count2 = 0, x = 0;
  83. size_t j = Start.size()*2;
  84. for (size_t i = 0; i < j; i++)
  85. {
  86. if (Start.empty() || End.empty())
  87. break;
  88. long long tmp1;
  89.  
  90. if (Start.front().first <= End.front().first)
  91. {
  92. ++count1;
  93. tmp1 = Start.front().first;
  94. Start.erase(Start.begin());
  95.  
  96. }
  97. else
  98. {
  99. ++count2;
  100. End.erase(End.begin());
  101. }
  102. if (count < count1 - count2)
  103. {
  104. count = count1 - count2;
  105. x = tmp1;
  106.  
  107. }
  108. }
  109. if (x > Xm)
  110. {
  111. x = Ym + Xm - x;
  112. fout << count << " " << Xm << " " << x << endl;
  113. }
  114. else
  115. {
  116. fout << count << " " << x << " " << Ym << endl;
  117. }
  118. return 0;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement