http://acm.hdu.edu.cn/showproblem.php?pid=5738
题意就是给你n个点,问你有多少个集合符合至少有两个点在同一条线上。
思路就是把每个点遍历一下,然后用pair记录斜率,cnt表示每个点的和他重复的点的个数。
最后 (2^cnt-1)*(2^(pair个数)-1) 把这些都加一起就是答案了
AC代码:
#include<stdio.h>
#include<map>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
using namespace std;
typedef pair<int,int> pr;
struct node{
long long x,y;
}p[1100];
const int MM = 1e9 + 7;
long long gcd(long long p, long long q){
return q ? gcd(q, p % q) : p;
}
const int mod=1e9+7;
long long fun(long long p){
if (p == 0) return 1;
long long tt = fun(p / 2);
tt = tt * tt % MM;
if (p & 1) return tt * 2 % MM;
else return tt;
}
void upd(long long &x, long long y){
x += y;
if (x >= MM) x -= MM;
}
int main()
{
map< pair <int,int> ,int> mp;
int t,n,i,j,cnt;
long long ans;
while(~scanf("%d",&t)){
while(t--){
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%lld%lld",&p[i].x,&p[i].y);
}
ans=0;
for(int i=0;i<n;i++)
{
mp.clear();
cnt=0;
for(int j=i+1;j<n;j++){
long long x=p[i].x-p[j].x,y=p[i].y-p[j].y;
if(x<0){
y=-y;x=-x;
}
//int flag=1;
int r= gcd(fabs(x),fabs(y));
if(x==0 && y==0)
cnt++;
else if(x==0){
mp[pr(0,1)]++;
}
else if(y==0){
mp[pr(1,0)]++;
}
else{
x=x/r,y=y/r;
mp[pr(x,y)]++;
}
}
map<pr,int> ::iterator it;
long long re=1;
for(it=mp.begin();it!=mp.end();it++)
upd(re,(fun(it->second)-1));
upd(ans,re*fun(cnt)%mod-1);
}
cout<<ans<<endl;
}
}
return 0;
}