这题很容易知道求得是共线的集合,其中点数要>=2
先按x递增,x相同y递增排序点,然后枚举必取到点,以该点为中心,极坐标排序该点以后的点(atan2精度不够,建议用叉积判断),计算下就可以了,注意重点的情况
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
using namespace std;
typedef long long LL;
const int M=1000000007;
const int N=1000+10;
const double pi=2.0*acos(0.0);
struct Node{
int x,y;
}a[N];
int n;
LL bit[N];
int b[N];
bool cmp(Node i,Node j){return ((i.x<j.x)||(i.x==j.x && i.y<j.y));}
bool cmp2(int i,int j){
return (LL)a[i].x*a[j].y-(LL)a[j].x*a[i].y>=0;//用叉积代替atan2;atan2的精度似乎不够
}
void work()
{
scanf("%d",&n);
for (int i=1;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].y);
sort(a+1,a+n+1,cmp);
LL Res=n*(n-1)/2;
for (int i=1;i<=n;i++){
Node t;t.x=a[i].x,t.y=a[i].y;
for (int j=i;j<=n;j++){
a[j].x-=t.x,a[j].y-=t.y;
}
int k=0;
for (int j=i+1;j<=n;j++)if (a[j].x==a[i].x && a[j].y==a[i].y) k++;//same
for (int j=i+k+1;j<=n;j++) b[j]=j;
sort(b+i+k+1,b+n+1,cmp2);
LL Ans=bit[k]-k-1;
for (int j=i+k+1;j<=n;j++){
int u=j;while (u<n && (LL)a[b[j]].x*a[b[u+1]].y-(LL)a[b[u+1]].x*a[b[j]].y==0)u++;
int m=u-j+1;
Ans=(Ans+(LL)(bit[k]-1)*(bit[m]-1)%M+(bit[m]-m-1)%M)%M;
j=u;
}
Res=(Res+Ans+M)%M;
for (int j=i;j<=n;j++)a[j].x+=t.x,a[j].y+=t.y;
}
cout<<(Res+M)%M<<endl;
}
int main()
{
//freopen("1.txt","r",stdin);
bit[0]=1;for (int i=1;i<N;i++)bit[i]=(bit[i-1]+bit[i-1])%M;
int Case;scanf("%d",&Case);
while (Case--)work();
return 0;
}