1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
| #include <bits/stdc++.h> #define maxn 800005 #define int long long using namespace std;
const long long eps = 0; template<typename T> struct TPoint{ T x, y; int color; TPoint(){} TPoint(T _x, T _y){ x = _x; y = _y; } TPoint(T _x, T _y, int c){ x = _x; y = _y; color = c; } TPoint(TPoint p, int _c){ x = p.x; y = p.y; color = _c; } friend TPoint operator +(const TPoint &a, const TPoint &b){ return TPoint(a.x + b.x, a.y + b.y); } friend TPoint operator -(const TPoint &a, const TPoint &b){ return TPoint(a.x - b.x, a.y - b.y); } friend double operator *(const TPoint &a, const TPoint &b){ return a.x * b.x + a.y * b.y; } friend double operator ^(const TPoint &a, const TPoint &b){ return a.x * b.y - a.y * b.x; } friend bool operator ==(const TPoint &a, const TPoint &b){ return abs(a.x - b.x) <= eps && abs(a.y - b.y) <= eps; } T len2(){ return x * x + y * y; } T angle(){ return atan2(y, x); } int toleft(const TPoint &a){ auto t = (*this) ^ a; return (t > eps) - (t < -eps); } void print(){ cout << "[Point] " << x << " " << y << " " << color << '\n'; } }; using Point = TPoint<long long>; bool argcmpC(const Point &a, const Point &b){ auto Quad = [](const Point &a){ if(a.y < -eps) return 1; if(a.y > +eps) return 4; if(a.x < -eps) return 5; if(a.x > +eps) return 3; return 2; }; int qa = Quad(a), qb = Quad(b); if(qa != qb) return qa < qb; auto cross = (a ^ b); return cross > eps; } int t, n, ans, sW, sB; Point P[maxn], Basic; vector<pair<Point, array<int, 2>>> trans(vector<Point> &P){ map<Point, array<int, 2>, decltype(&argcmpC)> uni{&argcmpC}; vector<pair<Point, array<int, 2>>> res; for(auto x : P) uni[x][x.color]++; for(auto x : uni) res.push_back(x); return res; } int solve(vector<Point> &P, Point &B){ int cntL[2] = {}, ans = 0; vector<pair<Point, array<int, 2>>> uP = trans(P); int siz = uP.size(); uP.insert(uP.end(), uP.begin(), uP.end()); int l = 0, r = 0; while(l < siz){ if(l > 0 && uP[l - 1].first.toleft(uP[l].first) == 1){ cntL[0] -= uP[l].second[0]; cntL[1] -= uP[l].second[1]; } while(r < uP.size() && (l == r || uP[l].first.toleft(uP[r].first) == 1)){ if(l != r){ cntL[0] += uP[r].second[0]; cntL[1] += uP[r].second[1]; } r++; } int cntR[2] = {}, cntO[2] = {}; cntO[B.color]++; cntO[0] += uP[l].second[0]; cntO[1] += uP[l].second[1]; if(r < uP.size() && !(uP[l].first == uP[r].first) && uP[l].first.toleft(uP[r].first) == 0){ cntO[0] += uP[r].second[0]; cntO[1] += uP[r].second[1]; } cntR[0] = sW - cntL[0] - cntO[0]; cntR[1] = sB - cntL[1] - cntO[1]; int bas = cntO[0] + cntO[1]; ans = max({ans, bas + cntL[0] + cntR[1], bas + cntL[1] + cntR[0]}); l++; } return ans; }
signed main(void) { while(cin >> n && n) { sW = sB = ans = 0; for(int i = 1; i <= n; i++){ int x, y, c; cin >> P[i].x >> P[i].y >> P[i].color; P[i].color == 1 ? sB++ : sW++; } for(int i = 1; i <= n; i++){ Basic = P[i]; vector<Point> np; for(int j = 1; j <= n; j++){ if(i != j){ np.push_back(Point(P[j] - Basic, P[j].color)); } } ans = max(ans, solve(np, Basic)); } cout << ans << '\n'; } return 0; }
|