ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • (useless) furthestPoints (rotating calipers)
    232's competitive-programming templates./geometry 2024. 10. 23. 16:26

    upd : now all in Geometry..

    std::pair<Point, Point> furthestPoints(const std::vector<Point>& pts) {
      assert(!pts.empty());
      auto hull = getConvexHull(pts);
      int n = hull.size();
      G max_dist = -1;
      std::pair<Point, Point> res;
      for (int i = 0, j = 0; i < n; ++i) {
        if (auto d = dist2(hull[i], hull[j]); max_dist < d) {
          max_dist = d;
          res = {hull[i], hull[j]};
        }
        while (ccw(hull[i], hull[(i + 1) % n], hull[(i + 1) % n] + hull[(j + 1) % n] - hull[j]) >= 0) {
          j = (j + 1) % n;
          if (auto d = dist2(hull[i], hull[j]); max_dist < d) {
            max_dist = d;
            res = {hull[i], hull[j]};
          }
          if (i == j) {
            break;
          }
        }
      }
      return res;
    }

    '232's competitive-programming templates. > geometry' 카테고리의 다른 글

    Geometry  (0) 2024.10.27
Designed by Tistory.