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.
Sample Input
3
3
1 1
1 1
1 1
3
0 0
0 1
1 0
1
0 0
Sample Output
4
3
0
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.
Sample Input
3
3
1 1
1 1
1 1
3
0 0
0 1
1 0
1
0 0
Sample Output
4
3
0
题意:大致就是说给出很多点,可能有在相同位置的点,这样也算是两个点,问两点共线的情况能有多少种。
思路是将两两点之间变成向量,然后统计向量。首先把点按照 x 坐标从小到大排序,相同的 x 按照 y 从小到大排序。我们确定好一个规律,当有n个点共线时,组合个数为:2^n-n-1。
然后向量分为两种:第一种是:(0,0)这样的向量代表有多个点是在一个坐标上,此时我们就要先计算出在一个点上有多少个情况共线,这样的向量有n个,就代表着有n+1个点,通过公式我们可以计算出多个点在一个坐标上时的组合个数,通过上面的公式:2^(n+1)-n-2。第二种是:向量中都不为0,此时组合的个数为:前面得到的在一个坐标上点的个数的组合数乘上向量个数的组合数,前面的在一个坐标上的数量为n1,当前向量个数为n2。通过公式可以得到:(2^n1-1)*(2^(n2+1)-1)。把这两种加起来就是以一个点为起点时的共线的组合个数,最后遍历全部再相加就是总的数量了。
注意数据有点大,要全部用long long
///HDU 5738
#include <cstdio>
#include <cstdlib>
#include <map>
#include <iterator>
#include <algorithm>
using namespace std;
long long GCD(long long a, long long b)
{
if (b == 0)
return a;
return GCD(b, a%b);
}
long long MOD_EXP(long long a, long long b, long long c) ///a^b%c
{
long long res, t;
res = 1%c;
t = a%c;
while (b)
{
if (b & 1)
res = res * t % c;
t = t * t % c;
b /= 2;
}
return res;
}
struct point
{
long long x, y;
bool operator < (const point &p) const
{
if (this->x == p.x)
return this->y < p.y;
else
return this->x < p.x;
}
};
point pts[1100];
map<point, long long> cnt;///记录不同向量的个数
map<point, long long> vis;
map<point, long long>::iterator it;
const long long MOD = 1000000007;
bool cmp(point a, point b)
{
return a < b;
}
int main()
{
long long T, n;
scanf("%I64d", &T);
while (T--)
{
vis.clear();
cnt.clear();
long long ans = 0;
scanf("%I64d", &n);
for (long long i = 0; i < n; ++i)
scanf("%I64d %I64d", &pts[i].x, &pts[i].y);
sort(pts, pts + n);
for (long long i = 0; i < n; ++i)
{
if (vis[pts[i]])
continue;
cnt.clear();
for (long long j = i + 1; j < n; ++j)
{
long long x = pts[j].x - pts[i].x;
long long y = pts[j].y - pts[i].y;
if (x < 0)
{
x = -x;
y = -y;
}
long long gcd = GCD(x, abs(y));
if (x != 0 && y != 0)
{
if (x == 0)
y = 1;
if (y == 0)
x = 1;
}
if (gcd != 0)///prime each other
{
x /= gcd;
y /= gcd;
}
point tmp;
tmp.x = x;
tmp.y = y;
cnt[tmp]++;
}
long long k;
point same;
same.x = 0;
same.y = 0;
long long tmp;
tmp = cnt[same];
for (it = cnt.begin(); it != cnt.end(); ++it)
{
if (it->first.x == 0 && it->first.y == 0)///向量为(0,0)
{
k = MOD_EXP(2, it->second + 1, MOD);
k = k - it->second - 2;
ans += k;
ans %= MOD;
}
else
{
k = MOD_EXP(2, it->second, MOD);
k = k - 1;
ans += (k * (MOD_EXP(2, tmp + 1, MOD) - 1));
ans %= MOD;
}
}
vis[pts[i]] = 1;
}
ans %= MOD;
printf("%I64d\n", ans);
}
return 0;
}