Pagini recente » Cod sursa (job #1403658) | Cod sursa (job #3230966) | Cod sursa (job #564567) | Cod sursa (job #2151046) | Cod sursa (job #772786)
Cod sursa(job #772786)
#include<iostream>
#include<cmath>
#include<fstream>
#include<algorithm>
#define Error 0.0001
using namespace std;
struct punct{double x,y;};
struct dr{double a,b,c;};
punct a[1600];
int n,sol;
int cmp(punct A, punct B)
{
if (A.x<B.x)
return 1;
if (A.x==B.x)
if (A.y<B.y)
return 1;
return 0;
}
void ec_dr(punct a, punct b, dr &ab)
{
ab.a=b.y-a.y;
ab.b=a.x-b.x;
ab.c=a.x*a.y-a.x*b.y+a.y*b.x-a.y*a.x;
}
double dist_dr(punct a, dr d)
{
return abs(d.a*a.x+d.b*a.y+d.c)/sqrt(d.a*d.a+d.b*d.b);
}
double dist (punct a, punct b)
{
return sqrt( (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int main(void)
{
fstream f,g;
f.open("triang.in",ios::in);
g.open("triang.out",ios::out);
f>>n;
int i,j;
double rad=sqrt(3+0.0)/2;
for (i=1;i<=n;i++)
f>>a[i].x>>a[i].y;
sort(a+1,a+1+n,cmp);
for (i=1;i<=n-2;i++)
for (j=i+1;j<=n-1;j++)
{
double l1=dist(a[i],a[j]);
dr d;
ec_dr(a[i],a[j],d);
int st=j+1,dr=n,mij;
while (st<=dr)
{
mij=(st+dr)/2;
double dist;
dist=dist_dr(a[mij],d);
if (abs(dist-rad*l1)<Error)
{
sol++;
break;
}
if (dist>rad*l1)
st=mij+1;
else
dr=mij-1;
}
}
g<<sol;
}