Advertisement
Guest User

Untitled

a guest
Oct 24th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.02 KB | None | 0 0
  1. #include <CGAL/Exact_predicates_exact_constructions_kernel.h>
  2. #include <iostream>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <stdexcept>
  6.  
  7. using namespace std;
  8.  
  9. typedef CGAL::Exact_predicates_exact_constructions_kernel K;
  10.  
  11. bool beats(K::Ray_2 *lhs, K::Ray_2 *rhs, bool and_equal)
  12. {
  13.     if (!CGAL::do_intersect(*lhs, *rhs))
  14.         return false;
  15.     auto inter = CGAL::intersection(*lhs, *rhs);
  16.     if (const K::Point_2* inter_point = boost::get<K::Point_2>(&*inter))
  17.     {
  18.         if (and_equal)
  19.             return CGAL::squared_distance(lhs->source(), *inter_point) <= CGAL::squared_distance(rhs->source(), *inter_point);
  20.         else
  21.             return CGAL::squared_distance(lhs->source(), *inter_point) < CGAL::squared_distance(rhs->source(), *inter_point);
  22.     }
  23.     throw runtime_error("strange ray intersection");
  24. }
  25.  
  26. void testcase()
  27. {
  28.     int n;
  29.     long long y_0, x_1, y_1;
  30.     cin >> n;
  31.     vector< pair<K::Ray_2, int> > rays;
  32.     for (int i = 0; i < n; ++i)
  33.     {
  34.         cin >> y_0 >> x_1 >> y_1;
  35.         K::Ray_2 ray = K::Ray_2(K::Point_2(0, y_0), K::Point_2(x_1, y_1));
  36.         rays.push_back(make_pair(ray, i));
  37.     }
  38.  
  39.     sort(rays.begin(), rays.end(), [ ](const pair<K::Ray_2, int>& lhs, const pair<K::Ray_2, int>& rhs) { return lhs.first.source() < rhs.first.source(); });
  40.  
  41.     vector< pair<K::Ray_2, int> > to_infinity;
  42.     to_infinity.push_back(rays[0]);
  43.  
  44.     for (int i = 1; i < n; ++i)
  45.     {
  46.         while (!to_infinity.empty() && beats(&rays[i].first, &(*to_infinity.rbegin()).first, false)) to_infinity.pop_back();
  47.         if (to_infinity.empty() || !beats(&(*to_infinity.rbegin()).first, &rays[i].first, true)) to_infinity.push_back(rays[i]);
  48.     }
  49.  
  50.     sort(to_infinity.begin(), to_infinity.end(), [ ] (const pair<K::Ray_2, int>& lhs, const pair<K::Ray_2, int>& rhs) { return lhs.second < rhs.second; });
  51.  
  52.     for (auto item : to_infinity)
  53.         cout << item.second << " ";
  54.     cout << endl;
  55. }
  56.  
  57. int main()
  58. {
  59.     int T;
  60.     cin >> T;
  61.     while (T--) testcase();
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement