Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <vector>
  4. #include <map>
  5.  
  6. using namespace std;
  7.  
  8. int find_chapter(int X, int Y) {
  9. if (X >= 0) {
  10. if (Y >= 0) {
  11. return 1;
  12. } else {
  13. return 4;
  14. }
  15. } else {
  16. if (Y >= 0) {
  17. return 2;
  18. } else {
  19. return 3;
  20. }
  21. }
  22. }
  23.  
  24. struct coordinate {
  25. int X;
  26. int Y;
  27. int chapter;
  28. int distance = 0;
  29.  
  30. int find_distance() {
  31. if (this->X != 0 && this->Y != 0) {
  32. distance = min(abs(this->X), abs(this->Y));
  33. }
  34. }
  35.  
  36. void set_X(int X) {
  37. this->X = X;
  38. chapter = find_chapter(X, Y);
  39. distance = find_distance();
  40. }
  41.  
  42. void set_Y(int Y) {
  43. this->Y = Y;
  44. chapter = find_chapter(X, Y);
  45. distance = find_distance();
  46. }
  47.  
  48. int get_X() const{
  49. return X;
  50. }
  51.  
  52. int get_Y() const{
  53. return Y;
  54. }
  55.  
  56. int get_Chapter() const{
  57. return chapter;
  58. }
  59.  
  60. int get_Distance() const {
  61. return distance;
  62. }
  63. };
  64.  
  65. vector<coordinate> coordinates;
  66. coordinate ULTIMATE_COORDINATE_JAJAJA;
  67.  
  68. int find_Nearest_Distance(int chapter) {
  69. int Min_Distance = 0;
  70. for (const auto &coordinate : coordinates) {
  71. if (coordinate.get_Chapter() == chapter) {
  72. if (Min_Distance == 0) {
  73. Min_Distance = coordinate.get_Distance();
  74. continue;
  75. }
  76. if (Min_Distance > coordinate.get_Distance()) {
  77. Min_Distance = coordinate.get_Distance();
  78. ULTIMATE_COORDINATE_JAJAJA = coordinate;
  79. }
  80. }
  81. }
  82.  
  83. return Min_Distance;
  84. }
  85.  
  86.  
  87. int main() {
  88.  
  89. int N = 0, X = 0, Y = 0, buffer_value = -1, max_quarter = 0;
  90. coordinate temp_coor;
  91. cin >> N;
  92.  
  93. map<int, int> quarters;
  94.  
  95. for (int i = 0; i < N; i++) {
  96. cin >> X >> Y;
  97. temp_coor.set_X(X);
  98. temp_coor.set_Y(Y);
  99. coordinates.push_back(temp_coor);
  100.  
  101. quarters[temp_coor.get_Chapter()]++;
  102. }
  103.  
  104. for (const auto&[chapter, value] : quarters) {
  105. if (value > buffer_value) {
  106. buffer_value = value;
  107. max_quarter = chapter;
  108. } else if (value == buffer_value) {
  109. max_quarter = (find_Nearest_Distance(max_quarter) < find_Nearest_Distance(chapter)) ? max_quarter : chapter;
  110. }
  111. }
  112.  
  113. cout << "K = " << max_quarter << "\nM = " << buffer_value << "\nA = (" << ULTIMATE_COORDINATE_JAJAJA.get_X() <<
  114. "," << ULTIMATE_COORDINATE_JAJAJA.get_Y() << ")\n"<< "R = " << ULTIMATE_COORDINATE_JAJAJA.get_Distance();
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement