ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1207. Median on the Plane

Why does a simple sort of pairs + finding the median not work?
Posted by sweepea 11 Nov 2024 16:21
All the test cases I've come up with have been solved correctly by this method but no AC :(

code:
```
#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  cin >> n;

  vector<vector<int>> x(n, vector<int>(3, 0));

  for (int i = 0; i < n; i++) {
    cin >> x[i][0];
    cin >> x[i][1];
    x[i][2] = i + 1;
  }

  sort(x.begin(), x.end());

  auto med = (n - 1) / 2;

  cout << x[med][2] << " " << x[med + 1][2];
}

```

Edited by author 11.11.2024 16:23

Edited by author 11.11.2024 16:23
Re: Why does a simple sort of pairs + finding the median not work?
Posted by sweepea 12 Nov 2024 14:43
To answer my own question.

The above code will select for the 2 median points. These don't necessarily create a median line.

Consider the following test case:
4
0 10
1 1
2 2
3 10



The above alogorithm would select (1, 1) and (2,2), which partitions the plane into a section with 2 points, and a section with 0 points; the above approach is incorrect.