给出平面上nn个点. 对于点xx,定义f(x)f(x)为有多少个四边形(不要求凸)能把这个点包在内部

求所有点的f(x)f(x)之和

n2500n \le 2500

CF1284E

Solution

先枚举XX,然后计算f(X)f(X)

考虑把XX看做原点,把所有点按XX的极角排序,统计不满足条件的四边形个数

把不满足条件的四边形放在极角序最小的点AA上统计,发现不合法的情况一定是,四边形上的所有点都在射线AXAX的上方,如图所示

20-1-20-1

two pointers扫一下即可

Code

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
#include <iostream>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <climits>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <bitset>
#include <fstream>
#include <tr1/unordered_map>
#include <assert.h>

#define x first
#define y second
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back
#define DEBUG(x) cout << #x << " = " << x << endl;

using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }
template <typename T> inline T read ()
{
T sum = 0, fl = 1; char ch = getchar();
for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
return sum * fl;
}

inline void proc_status ()
{
ifstream t ("/proc/self/status");
cerr << string (istreambuf_iterator <char> (t), istreambuf_iterator <char> ()) << endl;
}

const int MAXN = 5000;

int N;
pii A[MAXN + 5], P[MAXN + 5];

inline int check (pii p)
{
if (p.x >= 0 && p.y >= 0) return 0;
if (p.x < 0 && p.y >= 0) return 1;
if (p.x < 0 && p.y < 0) return 2;
return 3;
}

inline LL cross (pii a, pii b) { return (LL) a.x * b.y - (LL) a.y * b.x; }

inline int cmp (pii a, pii b)
{
if (check (a) == check (b)) return cross (a, b) > 0;
return check (a) < check (b);
}

LL ans;

inline LL C3 (int x) { return (LL) x * (x - 1) * (x - 2) / 6; }

inline void calc (int s)
{
int M = 0;
for (int i = 1; i <= N; ++i) if (i != s) P[++M] = mp (A[i].x - A[s].x, A[i].y - A[s].y);
sort (P + 1, P + M + 1, cmp);

for (int i = 1; i <= M; ++i) P[i + M] = P[i];

int p = 1;
for (int i = 1; i <= M; ++i)
{
while (p < i + M && cross (P[i], P[p]) >= 0) ++p;
int up = p - i - 1;
if (up >= 3) ans -= (LL) C3 (up);
}
}

inline void Solve ()
{
ans = (LL) (LL)N * (N - 1) * (N - 2) * (N - 3) * (N - 4) / 24;
for (int i = 1; i <= N; ++i) calc (i);
cout << ans << endl;
}

inline void Input ()
{
N = read<int>();
for (int i = 1; i <= N; ++i) A[i].x = read<int>(), A[i].y = read<int>();
}

int main ()
{

#ifdef hk_cnyali
freopen("E.in", "r", stdin);
freopen("E.out", "w", stdout);
#endif

Input ();
Solve ();

return 0;
}