Pagini recente » Cod sursa (job #430034) | Cod sursa (job #92632) | Cod sursa (job #646942) | Cod sursa (job #397566) | Cod sursa (job #2581244)
#include <iostream>
#include <algorithm>
#include <fstream>
#include <cmath>
using namespace std;
ifstream f("triang.in");
ofstream g("triang.out");
const double Err=0.001;
struct pct
{
double x,y;
} p[1505];
int n,nrtriang;
bool comp(pct a,pct b)
{
if(a.x==b.x)
return a.y<b.y;
else
a.x<b.x;
}
int BinSearch(double x,double y)
{
int low=1,high=n,mid;
while(low<=high)
{
mid=(low+high)/2;
if(abs(p[mid].x-x)<=Err && abs(p[mid].y-y)<=Err)
return 1;
else
{
if(p[mid].x<x)
high=mid+1;
else
low=mid-1;
}
}
return 0;
}
int main()
{
f>>n;
for(int i=1; i<=n; i++)
f>>p[i].x>>p[i].y;
sort(p+1,p+n+1,comp);
for(int i=1; i<=n; i++)
for(int j=i+1; j<=n; j++)
{
double m,xm,ym,x1,y1,x2,y2,dist;
pct a,b;
a.x=p[i].x;
a.y=p[i].y;
b.x=p[j].x;
b.y=p[j].y;
xm=(a.x+b.x)/2;
ym=(a.y+b.y)/2;
dist=(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
dist*=3;
if(abs(a.x-b.x)<=Err)
{
y1=ym;
y2=ym;
x1=xm+0.5d*sqrt(dist);
x2=xm-0.5d*sqrt(dist);
}
else
{
m=(b.y-a.y)/(b.x-a.x);
y1=ym+0.5d*sqrt(dist/(1+m*m));
x1=xm+0.5d*m*sqrt(dist/(1+m*m));
y2=ym-0.5d*sqrt(dist/(1+m*m));
x2=xm-0.5d*m*sqrt(dist/(1+m*m));
}
nrtriang+=BinSearch(x2,y2);
nrtriang+=BinSearch(x1,y1);
}
g<<nrtriang/3;
return 0;
}