Pagini recente » Cod sursa (job #728029) | Cod sursa (job #87912) | Cod sursa (job #747870) | Cod sursa (job #2486033) | Cod sursa (job #2307773)
#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;
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(abs(a[mij].x-p.x)<EPS && abs(a[mij].y-p.y)<EPS)
{
return 1;
}
else
{
if(abs(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=abs(a[i].x-mx);
disty=abs(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;
}