cf#308-D - Vanya and Triangles-求平面点集中三角形个数-枚举-n^2logn

http://codeforces.com/contest/552/problem/D


给n,n个点,求构成的面积非零的三角形个数。。


共c(n,3)种,要除去三点共线的即可咯


枚举点i ,对所有(j>i)的点 ,求一遍斜率,最后  与点i构成斜率为K的点数有x个,那么便有C(x,2)个共线三角形咯。  全部累加起来最后 被c(n,3)减去就是答案了咯

统计斜率部分用map比较方便咯

【注意爆int】【注意double精度问题 】

#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iostream>
using namespace std;

const double pi=acos(-1.0);
double eps=0.000001; 
__int64 min(__int64 a,__int64 b)
{return a<b?a:b;} 
__int64 max(__int64 a,__int64 b)
{return a>b?a:b;}

 
struct POINT 
{ 
	int x; 
	int y; 
	POINT(double a=0, double b=0) { x=a; y=b;} //constructor 
	double jijiao;
};
POINT p[2005];
__int64 gcd(__int64 a,__int64 b)
{
	if (!b)return a;
	else return gcd(b,a%b);
}
 double get(__int64 i,__int64 j)
 {
	__int64 y=p[i].y-p[j].y;
	__int64 x=p[i].x-p[j].x; 
	if (!x)return 100000;
	__int64 gd=gcd(x,y);
	x/=gd;
	y/=gd;
	 return (y*1.0/x);
 }

 map <double,__int64 >sb;
 map <double,__int64 >::iterator it;;
int main() 
{

	__int64 n;
	scanf("%I64d",&n);
	__int64 i,j; 
	for (i=1;i<=n;i++) 
		scanf("%d%d",&p[i].x,&p[i].y);   
	__int64 ans=0;
	for (i=1;i<=n;i++)
	{
		sb.clear();
		for(j=i+1;j<=n;j++)
		{ 
			 double k=get(i,j);
			sb[k]++;
		}
		for (it=sb.begin();it!=sb.end();it++)
		{ 
			if (it->second>=2)
			ans+= (it->second)*(it->second-1)/2  ;
		}		 
	}
printf("%I64d\n",n*(n-1)*(n-2)/6-ans);
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值