Pagini recente » Cod sursa (job #1864528) | Cod sursa (job #1857904) | Cod sursa (job #18361) | Cod sursa (job #1404796) | Cod sursa (job #2979561)
#include<bits/stdc++.h>
using namespace std;
ifstream f("patrate3.in");
ofstream g("patrate3.out");
int n,sol;
struct pct
{
int x,y;
} a[1005];
bool comp(pct X,pct Y)
{
if(X.x==Y.x)
return X.y<Y.y;
return X.x<Y.x;
}
bool cautare(pct r)
{
int X=r.x;
int Y=r.y;
int st=1,dr=n;
while(st<=dr)
{
int mj=(st+dr)/2;
if(a[mj].x<X)
st=mj+1;
else if(a[mj].x>X)
dr=mj-1;
else if(a[mj].x==X)
{
if(a[mj].y<=Y)
st=mj+1;
else
dr=mj-1;
}
}
if(a[st-1].x==X&&a[st-1].y==Y)
return true;
return false;
}
int main()
{
f>>n;
for(int i=1; i<=n; i++)
{
double X,Y;
f>>X>>Y;
a[i].x=round(X*10000);
a[i].y=round(Y*10000);
}
sort(a+1,a+n+1,comp);
for(int i=1; i<n; i++)
for(int j=i+1; j<=n; j++)
if(a[i].x<a[j].x&&a[i].y<=a[j].y)
{
pct x1;
x1.x=a[i].x-(a[j].y-a[i].y);
x1.y=a[i].y+(a[j].x-a[i].x);
pct x2;
x2.x=a[j].x-(a[j].y-a[i].y);
x2.y=a[j].y+(a[j].x-a[i].x);
if(cautare(x1)&&cautare(x2))
sol++;
}
g<<sol;
return 0;
}