http://acm.hdu.edu.cn/showproblem.php?pid=5784
暴力每一个点,然后以这个点为原点做一个极角排序,尺取法求有多少个钝角,平角等等,为了不重复枚举,可以对每个点都只算向左180度以内的(利用叉乘正负判断)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct point
{
long long x,y;
point(ll x=0,ll y=0):x(x),y(y){}
point operator - (const point &t)const
{
return point(x-t.x,y-t.y);
}
ll operator * (const point &t)const//有向面积,逆时针为正
{
return x*t.y-y*t.x;
}
ll operator ^ (const point &t)const
{
return t.x*x+t.y*y;
}
bool operator < (const point &t)const
{
int t1=0,t2=0;
if(y>0||y==0&&x>0)t1=1;
if(t.y>0||t.y==0&&t.x>0)t2=1;
if(t1!=t2)
return t1>t2;
if((*this)*t==0)
return ((*this)^(*this))<(t^t);
return (*this)*t>0;
}
}p[2005],te[4005];
int main()
{
int n,i,j;
ll ans,tmp;
while(cin>>n)
{
ans=0,tmp=0;
for(i=0;i<n;i++)
scanf("%lld %lld",&p[i].x,&p[i].y);
for(i=0;i<n;i++)
{
int tot=0;
for(j=0;j<n;j++)
{
if(j!=i)
{
te[tot++]=p[j]-p[i];
}
}
sort(te,te+tot);
for(j=0;j<tot;j++)
{
te[j+tot]=te[j];
}
int now=0;
for(j=1;j<tot;j++)//0度角个数
{
if((te[j]*te[j-1])==0&&(te[j]^te[j-1])>0)
now++;
else
now=0;
tmp+=now;
}
int i1=1,i2=1;
for(j=0;j<tot;j++)
{
i1=max(i1,j+1);
while(i1<j+tot&&(te[j]*te[i1])>=0&&(te[j]^te[i1])>0)
i1++;
i2=max(i2,i1);
while(i2<j+tot&&(te[j]*te[i2])>0&&(te[j]^te[i2])<=0)
i2++;
ans+=(i2-i1);
}
}
cout<<1ll*n*(n-1)*(n-2)/6-ans-tmp/2<<endl;
}
}