Problem Description
Professor Zhang draws n points on the plane, which are conveniently labeled by 1,2,…,n. The i-th point is at (xi,yi). Professor Zhang wants to know the number of best sets. As the value could be very large, print it modulo 109+7.
A set P (P contains the label of the points) is called best set if and only if there are at least one best pair in P. Two numbers u and v (u,v∈P,u≠v) are called best pair, if for every w∈P, f(u,v)≥g(u,v,w), where f(u,v)=(xu−xv)2+(yu−yv)2−−−−−−−−−−−−−−−−−−−√ and g(u,v,w)=f(u,v)+f(v,w)+f(w,u)2.
Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
The first line contains an integer n (1≤n≤1000) – then number of points.
Each of the following n lines contains two integers xi and yi (−109≤xi,yi≤109) – coordinates of the i-th point.
Output
For each test case, output an integer denoting the answer.
比赛时候我zz地用了一种sb的计数方案到死也没有调出来。赛后用了大涛哥的方案很快就过了。其实只需要枚举选中某个点的情况依次删去这些点就ok了。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1000000007;
int n;
struct node{
int x, y;
}rec[1050];
int gcd(int x, int y)
{
if(x==0)return y;
else return gcd(y%x, x);
}
bool operator ==(node const&a, node const&b)
{
return a.x==b.x&&a.y==b.y;
}
bool operator <(node const&a, node const&b)
{
if(a.x==b.x)return a.y<b.y;
return a.x<b.x;
}
node operator -(node const&a, node const&b)
{
node ans;
ans.x=a.x-b.x;ans.y=a.y-b.y;
int tmp=abs(gcd(ans.x, ans.y));
ans.x/=tmp;ans.y/=tmp;
if(ans.x<0){
ans.x=-ans.x;ans.y=-ans.y;
}
else if(ans.x==0)ans.y=abs(ans.y);
return ans;
}
ll Pow(ll base, int b)
{
ll ans=1;
while(b)
{
if(b&1)
{
ans=(ans*base)%mod;
}
base=(base*base)%mod;
b>>=1;
}
return ans;
}
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
ll ans=0;
scanf("%d", &n);
for(int i=1;i<=n;i++)
{
scanf("%d%d", &rec[i].x, &rec[i].y);
}
for(ll i=1;i<=n;i++)
{
map<node, int>mp;
int cnt=0;
for(ll j=i+1;j<=n;j++)
{
if(rec[j]==rec[i]){
cnt++;
continue;
}
else {
node tmp=rec[j]-rec[i];
mp[tmp]++;
}
}
ans+=Pow(2, cnt)-1+mod;
ans%=mod;
for(map<node, int>::iterator it=mp.begin();it!=mp.end();it++)
{
int p=it->second;
ans=(ans+(Pow(2, cnt)*((Pow(2, p)-1+mod)%mod))%mod)%mod;
}
}
printf("%lld\n", ans);
}
}``