codeforces 1284E

Topic Link

The meaning of problems

give n ( n 2500 ) n (n \ the 2500) point, to ensure that no three collinear, find the number of each point may be the other four points comprising programs and strict.

solution

Considered illegal by subtracting the number of programs with the total number of points first enumeration is included, then the total number is C n 1 4 C^{4}_{n-1} , Illegal program number is four points in a straight line through the side of the point is included, this need to press all points and relative position of a point included sorting polar angle, and swept past double pointer .
the complexity O ( n 2 l o g n ) O (n ^ 2logn)
(Note that when the polar angle sort require pretreatment atan2, or because too constant T out)

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=6e3+5;
inline int read(){
	char c=getchar();int t=0,f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
int n,cnt;
struct node{
	long long x,y;
	long double at;
}a[maxn],b[maxn];
inline int cross(node a,node b){
	return a.x*b.y-a.y*b.x;
} 
bool cmp(node a,node b){
	long double p=a.at,q=b.at;
	if(p!=q){
		return p<q;
	}
	return a.x<b.x;
}
signed main(){
	//freopen("5.in","r",stdin);
	//freopen("5.out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++){
		a[i].x=read(),a[i].y=read();
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		cnt=0;
		for(int j=1;j<=n;j++){
			if(i!=j){
				b[++cnt].x=a[j].x-a[i].x;
				b[cnt].y=a[j].y-a[i].y;
				b[cnt].at=atan2(b[cnt].y,b[cnt].x);
			//	printf("%.0lf %.0lf\n",b[cnt].x,b[cnt].y);
			}
		}
		sort(b+1,b+1+cnt,cmp);
		for(int i=cnt+1;i<=cnt*2;i++)b[i]=b[i-cnt];
		int tmp=(n-1)*(n-2)*(n-3)*(n-4)/24;
		for(int l=1,r=0;l<n;l++){
			for(r=max(r,l+1);r<l+n&&(cross(b[l],b[r])>0);r++);r--;
		//	printf("%lld %lld %.0lf %.0lf %.0lf %.0lf\n",l,r,b[l].x,b[l].y,b[r].x,b[r].y);
			if(r-l-2>0)
			tmp-=(r-l)*(r-l-1)*(r-l-2)/6;
			//if(r>=n-1)break;
		}
		//printf("%lld\n",tmp);
		ans+=tmp;
	}
	printf("%lld\n",ans);
	return 0;
}

Published 62 original articles · won praise 1 · views 994

Guess you like

Origin blog.csdn.net/wmhtxdy/article/details/103847548