Pagini recente » Cod sursa (job #549271) | Cod sursa (job #3193690) | Cod sursa (job #1618149) | Cod sursa (job #1253595) | Cod sursa (job #2310156)
#include <fstream>
#include <iostream>
#include <math.h>
#include <cmath>
#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,i,j,Counter;
int modul(int a,int b)
{
if(a-b>=0)
{
return (a-b);
}
else
{
return (-1)*(a-b);
}
}
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)
{
double p,q;
int st=1,dr=N,mij;
while(st<=dr)
{
mij=(st+dr)/2;
p=A.x-v[mij].x;
q=A.y-v[mij].y;
if(abs(p)<marja && abs(q)<marja)
{
return 1;
}
if(abs(p)<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.0;
mij.y=(v[i].y+v[j].y)/2.0;
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) && cautare(B))
{
Counter++;
}
}
return Counter/2;
}
int main()
{
citire();
sort(v+1,v+N+1,comparare);
fout<<numarare_patrate();
fin.close();
fout.close();
return 0;
}