fork download
  1. #include <cmath>
  2. #include <utility>
  3. #include <iostream>
  4. #include <queue>
  5. #include <vector>
  6. #include <memory>
  7. #include <string>
  8.  
  9. using coordinate = std::pair<double, double>;
  10. std::ostream& operator<<(std::ostream& os, const coordinate& c)
  11. {
  12. os << "(" << c.first << "," << c.second << ")";
  13. return os;
  14. }
  15.  
  16. int main()
  17. {
  18. const auto abs = [](const coordinate& c)
  19. {
  20. return std::sqrt(c.first * c.first + c.second + c.second);
  21. };
  22. const auto pred = [&abs](const coordinate& lhs, const coordinate& rhs)
  23. {
  24. return abs(lhs) < abs(rhs);
  25. };
  26.  
  27. using coordinate_queue
  28. = std::priority_queue<coordinate, std::vector<coordinate>, decltype(pred)>;
  29. coordinate_queue pq(pred);
  30. pq.emplace(3, 1);
  31. pq.emplace(4, 1);
  32. pq.emplace(5, 9);
  33. pq.emplace(2, 6);
  34. pq.emplace(5, 3);
  35. while (!pq.empty())
  36. {
  37. std::cout << pq.top() << std::endl;
  38. pq.pop();
  39. }
  40.  
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
(5,9)
(5,3)
(4,1)
(2,6)
(3,1)