Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <math.h>
- using namespace std;
- struct Point {
- int x;
- int y;
- int distance = sqrt(x * x + y * y);
- Point() : x(0), y(0) {}
- Point(int a, int b) : x(a), y(b) {}
- };
- struct CustomCompare
- {
- bool operator()(const Point lhs, const Point rhs)
- {
- if (lhs.distance == rhs.distance)
- {
- if (lhs.x == rhs.x)
- {
- return lhs.y > rhs.y;
- }
- else
- {
- return lhs.x > rhs.x;
- }
- }
- return lhs.distance > rhs.distance;
- }
- };
- int main()
- {
- int countAll, countClosest;
- cin >> countAll >> countClosest;
- priority_queue <Point, vector<Point>, CustomCompare> pq;
- for (size_t i = 0; i < countAll; i++)
- {
- int x, y;
- cin >> x >> y;
- Point p(x, y);
- pq.push(p);
- }
- for (size_t i = 0; i < countClosest; i++)
- {
- cout << pq.top().x << " " << pq.top().y << endl;
- pq.pop();
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement