hdu5738(极角排序)

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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值