Pagini recente » Cod sursa (job #1849455) | Cod sursa (job #1818177) | Cod sursa (job #891570) | Cod sursa (job #2484819) | Cod sursa (job #2129933)
#include<fstream>
#include<iostream>
#include<algorithm>
#define eps 1e-3
#define DN 1505
#define x first
#define y second
using namespace std;
ifstream fin("triang.in");
ofstream fout("triang.out");
int n,rez,st,dr,m;
pair<double,double>a[DN];
double a1,b1,c1,a2,b2,c2,l,c,d,ar;
double dist(int p1,int p2)
{
return (a[p1].x-a[p2].x)*(a[p1].x-a[p2].x)+(a[p1].y-a[p2].y)*(a[p1].y-a[p2].y);
}
int cautare()
{
c=(c2*a1-c1*a2)/(b1*a2-b2*a1);
if(abs(a1)>eps)
l=(-c1-b1*c)/a1;
else
l=(-c2-b2*c)/a2;
st=1;
dr=n;
while(st<dr)
{
m=(st+dr)/2;
if(a[m].x<l||(a[m].x==l&&a[m].y<c))
st=m+1;
else
dr=m;
}
if(abs(l-a[st].x)<eps&&abs(c-a[st].y)<eps)
return 1;
return 0;
}
int main()
{
fin>>n;
for(int i=1;i<=n;i++)
fin>>a[i].x>>a[i].y;
sort(a+1,a+n+1);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(i!=j)
{
d=dist(i,j);
ar=(d*sqrt(3))/2;
a1=2*(a[j].x-a[i].x);
b1=2*(a[j].y-a[i].y);
c1=-a[j].x*a[j].x+a[i].x*a[i].x-a[j].y*a[j].y+a[i].y*a[i].y;
a2=a[i].y-a[j].y;
b2=a[j].x-a[i].x;
c2=ar+a[i].x*a[j].y+a[j].x*a[i].y;
if(cautare())
rez++;
c2=-ar+a[i].x*a[j].y+a[j].x*a[i].y;
if(cautare())
rez++;
}
fout<<rez/3;
}