Advertisement
Guest User

Untitled

a guest
May 16th, 2020
548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.01 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. using Point = complex<long long>;
  6.  
  7. int quad(const Point& p) {
  8.   int x = p.real(), y = p.imag();
  9.   assert(x || y);
  10.   if (y < 0) return (x >= 0) + 2;
  11.   if (y > 0) return (x <= 0);
  12.   return (x <= 0) * 2;
  13. }
  14.  
  15. long long cross(Point a, Point b) {
  16.   return (conj(a) * b).imag();
  17. }
  18. long long det(Point a, Point b, Point c) {
  19.   return cross(b - a, c - a);
  20. }
  21.  
  22. int Solve(vector<Point> pts) {
  23.   int n = pts.size();
  24.   if (n == 1) return 1;
  25.  
  26.   vector<Point> v;
  27.   for (int i = 0; i < n; ++i) {
  28.     for (int j = 0; j < n; ++j) {
  29.       if (j == i) continue;
  30.       Point d = pts[j] - pts[i];
  31.       v.push_back(d);
  32.     }
  33.   }
  34.  
  35.   auto by_angle = [&](Point a, Point b) {
  36.     if (quad(a) != quad(b))
  37.       return quad(a) < quad(b);
  38.     return cross(a, b) > 0;  
  39.   };
  40.   sort(v.begin(), v.end(), by_angle);
  41.   // v.erase(unique(v.begin(), v.end(), by_angle), v.end());
  42.  
  43.   vector<int> order(n);
  44.   for (int i = 0; i < n; ++i) {
  45.     order[i] = i;
  46.   }
  47.  
  48.   int total = 0;
  49.   for (auto p : v) {
  50.     for (int i = 0; i < n; ++i) {
  51.       int at = i;
  52.       while (at > 0) {
  53.         long long d1 = cross(p, pts[order[at]]);
  54.         long long d2 = cross(p, pts[order[at - 1]]);
  55.         if (d1 < d2) {
  56.           swap(order[at], order[at - 1]);
  57.           --at;
  58.         } else break;
  59.       }
  60.     }
  61.  
  62.     int now = 0;
  63.     for (int i = 0; i < n;) {
  64.       int j = i + 1;
  65.       while (j < n && cross(p, pts[order[i]]) == cross(p, pts[order[j]]))
  66.         ++j;
  67.       int cnt = j - i;
  68.       if (cnt > 1)
  69.         now += cnt;
  70.       i = j;
  71.     }
  72.     now -= now % 2; now += 2;
  73.     now = min(now, n);
  74.  
  75.     total = max(total, now);
  76.   }
  77.  
  78.   return total;
  79. }
  80.  
  81. int main() {
  82.   // Test();
  83.  
  84.   int t; cin >> t;
  85.   for (int tt = 1; tt <= t; ++tt) {
  86.     int n; cin >> n;
  87.     vector<Point> pts;
  88.     for (int i = 0; i < n; ++i) {
  89.       long long x, y; cin >> x >> y;
  90.       pts.emplace_back(x, y);
  91.     }
  92.     cout << "Case #" << tt << ": " << Solve(pts) << '\n';
  93.   }
  94.   return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement