Pagini recente » Cod sursa (job #1148280) | Cod sursa (job #2068904) | Cod sursa (job #1782607) | Cod sursa (job #1173327) | Cod sursa (job #2310141)
#include <fstream>
#include <iostream>
#include <algorithm>
#define marja 0.00001
using namespace std;
ifstream fin("patrate3.in");
ofstream fout("patrate3.out");
typedef struct{
double x, y;
}punct;
punct v[1001];
int N,nr,i,j,Counter;
int modul(int a,int b)
{
if(a>b)
{
return a-b;
}
else
{
return b-a;
}
}
void citire()
{
fin>>N;
for(i=1;i<=N;i++)
{
fin>>v[i].x>>v[i].y;
}
}
int comparare(punct A,punct B)
{
if(A.x<B.x)
{
return 1;
}
else if(A.x==B.x && A.y<B.y)
{
return 1;
}
else
{
return 0;
}
}
int cautare(punct A)
{
int st=1,dr=N,mij;
while(st<=dr)
{
mij=(st+dr)/2;
if(modul(A.x,v[mij].x)<marja && modul(A.y,v[mij].y)<marja)
{
return 1;
}
if(modul(A.x,v[mij].x)<marja)
{
if(A.y<v[mij].y)
{
dr=mij-1;
}
else
{
st=mij+1;
}
}
else
{
if(A.x<v[mij].x)
{
dr=mij-1;
}
else
{
st=mij+1;
}
}
}
return 0;
}
int numarare_patrate()
{
for(i=1;i<=N-1;i++)
for(j=i+1;j<=N;j++)
{
punct A,B,mij;
mij.x=(v[i].x+v[j].x)/2;
mij.y=(v[i].y+v[j].y)/2;
A.x=mij.x-v[j].y+mij.y;
A.y=mij.y+v[j].x-mij.x;
B.x=mij.x+v[j].y-mij.y;
B.y=mij.y-v[j].x+mij.x;
if(cautare(A)!=0 && cautare(B)!=0)
{
Counter++;
}
}
return Counter;
}
int main()
{
citire();
sort(v+1,v+N+1,comparare);
fout<<numarare_patrate()/2;
fin.close();
fout.close();
return 0;
}