题意:统计平面内有多少个点共线,有重点
思路:显然没有重点的时候是个水题,这里统计共线我是用了斜率存进map里面,由于直接除会是double很容易挂,所以直接map<pair<>,int>这样来处理就可以解决了,然后算一下重点的贡献和不重点的贡献就可以了
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1005;
const int mod = 1e9+7;
#define LL long long
LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL qpow(LL a,LL b)
{
if(b<0)
return 0;
LL ans = 1;
a%=mod;
for(;b;b>>=1,a=(a*a)%mod)
if(b&1)
ans = (ans*a)%mod;
return ans;
}
struct Node
{
LL x,y;
}point[maxn];
bool cmp(Node a,Node b)
{
if(a.x==b.x)
return a.y<b.y;
return a.x<b.x;
}
map<pair<LL,LL>,int >vis;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
vis.clear();
LL ans = 0;
int n;
scanf("%d",&n);
for(int i = 1;i<=n;i++)
scanf("%lld%lld",&point[i].x,&point[i].y);
sort(point+1,point+1+n,cmp);
for(int i = 1;i<=n;i++)
{
vis.clear();
LL res = 1;
for(int j = i+1;j<=n;j++)
{
if(point[i].x==point[j].x && point[i].y==point[j].y)
res++;
else
{
LL dx = point[j].x-point[i].x;
LL dy = point[j].y-point[i].y;
LL gg = gcd(dx,dy);
if(gg!=0)
{
dx/=gg;
dy/=gg;
}
vis[make_pair(dx,dy)]++;
}
}
if(res>1)
{
ans+=(qpow(2,res-1)-1)%mod;
ans%=mod;
}
LL cnt = 0;
for(map<pair<LL,LL>,int>::iterator it = vis.begin();it!=vis.end();it++)
{
LL cnt=(it->second);
ans = (ans+((qpow(2,cnt)-1)*(qpow(2,res-1)))%mod)%mod;
}
}
printf("%lld\n",ans);
}
}
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 .
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.
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
Author
zimpha
Source