Pagini recente » Cod sursa (job #620276) | Cod sursa (job #2594235) | Cod sursa (job #1197703) | Cod sursa (job #225690) | Cod sursa (job #2307778)
#include <iostream>
#include <algorithm>
#include <fstream>
using namespace std;
ifstream f("patrate3.in");
ofstream g("patrate3.out");
struct punct
{
double x,y;
};
punct a[1001],mx,my,p3,p4;
int n,nr;
const double EPS=0.0001;
double modul(double x,double y)
{
if(x>y)
{
return x-y;
}
else
{
return y-x;
}
}
inline bool cmp(const punct a,const punct b)
{
if(a.x==b.x)
{
return a.y<b.y;
}
else
{
return a.x<b.x;
}
}
bool cautare_binara(punct p)
{
int st,dr,mij;
st=1;
dr=n;
while(st<=dr)
{
mij=(st+dr)/2;
if(modul(a[mij].x,p.x)<EPS && modul(a[mij].y,p.y)<EPS)
{
return 1;
}
else
{
if(modul(a[mij].x,p.x)<EPS)
{
if(p.y>a[mij].y)
{
st=mij+1;
}
else
{
dr=mij-1;
}
}
else
{
if(p.x>a[mij].x)
{
st=mij+1;
}
else
{
dr=mij-1;
}
}
}
}
return 0;
}
int main()
{
int i,j;
double distx,disty,mx,my;
f>>n;
for(i=1;i<=n;i++)
{
f>>a[i].x>>a[i].y;
}
sort(a+1,a+n+1,cmp);
for(i=1;i<n;i++)
{
for(j=i+1;j<=n;j++)
{
mx=(a[i].x+a[j].x)/2;
my=(a[i].y+a[j].y)/2;
distx=modul(a[i].x,mx);
disty=modul(a[i].y,my);
if(a[i].y<a[j].y)
{
p3.x=mx+disty;
p3.y=my-distx;
p4.x=mx-disty;
p4.y=my+distx;
}
else
{
p3.x=mx-disty;
p3.y=my-distx;
p4.x=mx+disty;
p4.y=my+distx;
}
nr=nr+cautare_binara(p3)*cautare_binara(p4);
}
}
g<<nr/2;
return 0;
}