Cod sursa(job #2594960)

Utilizator alex_benescuAlex Ben alex_benescu Data 6 aprilie 2020 20:23:51
Problema Triang Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.84 kb
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
struct P { double x,y; };
P a[1501];
int i,n,j;
double r;
long long k;
int C(P a,P b) { return a.x<b.x||(a.x==b.x&&a.y<b.y); }
int B(int p,int q,double c,double d) {
	int m=(p+q)/2;
	if(p>q)
      	return 0;
	if(fabs(c-a[m].x)<0.001&&fabs(d-a[m].y)<0.001)
      	return m;
    return a[m].x<c?B(m+1,q,c,d):B(p,m-1,c,d);
}
int main(){
	freopen("triang.in","r",stdin),freopen("triang.out","w",stdout),scanf("%d",&n);
	for(i=1;i<=n;i++)
      	scanf("%lf%lf",&a[i].x,&a[i].y);
	sort(a+1,a+n+1,C),r=sqrt(3);
	for(i=1;i<n-1;i++)
	for(j=i+1;j<n;j++)
		k=k+(B(j+1,n,(a[i].x+a[j].x)/2+r*(a[i].y-a[j].y)/2,(a[i].y+a[j].y)/2+r*(a[j].x-a[i].x)/2)?1:0)+
		(B(j+1,n,(a[i].x+a[j].x)/2+r*(a[j].y-a[i].y)/2,(a[i].y+a[j].y)/2+r*(a[i].x-a[j].x)/2)?1:0);
	printf("%lld",k);
}