一:叉乘可以判断一个点和一条线段的关系:
例如点A(X1,Y1),线段用向量点B(X2,Y2)和点C(X3,Y3)表示。
令函数Cross(A,B,C)为叉乘运算;令flag=Cross(A,B,C),则有flag=(X1-X3)(Y2-Y3)-(X2-X3)(Y1-Y3);
当flag>0的时候,点A在线段BC的右边;因为向量AC在向量BC的顺时针方向
当flag=0的时候,点A在直线BC上。这里是直线,不是线段,说明A也可能在线段BC的延长线上;
当flag<0的时候,点A在线段BC的左边;因为向量AC在向量BC的逆时针方向
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const LL mod=1e9+7;
const int maxn=709;
int n,t;
struct point
{
LL x,y;
point() {}
point(LL x,LL y):x(x),y(y) {}
};
typedef point Vector;
typedef point Point;
Vector operator - (Vector a, Vector b) //向量减法
{
return Vector(a.x - b.x, a.y - b.y);
}
LL Dot(Vector a, Vector b) //内积
{
return a.x*b.x + a.y*b.y;
}
LL Cross(Vector a, Vector b) //外积
{
return a.x*b.y - a.y*b.x;
}
point Tmp;//选好的起点
int Quadrant(point a) // 象限
{
if(a.x>0&&a.y>=0)
return 1;
if(a.x<=0&&a.y>0)
return 2;
if(a.x<0&&a.y<=0)
return 3;
if(a.x>=0&&a.y<0)
return 4;
}
bool cmp(point a,point b)
{
if(Quadrant(a-Tmp)==Quadrant(b-Tmp))
{
LL ans=Cross(a-Tmp,b-Tmp);
if(ans==0)
return a.x<b.x;
return ans>0;
}
return Quadrant(a-Tmp)<Quadrant(b-Tmp);
}
point p[maxn],tmp[maxn];
int main()
{
cin>>t;
while(t--)
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>p[i].x>>p[i].y;
tmp[i]=p[i];
}
LL ans=1ll*n*(n-1)*(n-2)*(n-3)/24;
for (int i=1;i<=n;i++ )
{
LL sub=1ll*(n-1)*(n-2)*(n-3)/6;
Tmp=tmp[i];
int now=0;
for (int j=1;j<=n;j++ )
{
if(j!=i)
p[++now]=tmp[j];
}
sort(p+1,p+1+now,cmp);
for(int i=1,j=1; i<=now; i++)
{
while(Cross(p[i]-Tmp,p[j]-Tmp)>=0)//尺取
{
j=j%now+1;
//j++;
if(j==i)
break;
}
LL len=(j-1-i+now)%now;
sub-=len*(len-1)/2;
}
ans-=sub;
}
printf("%lld\n",ans);
}
}