Pagini recente » Cod sursa (job #230677) | Cod sursa (job #212292) | Cod sursa (job #661068) | Cod sursa (job #2704159) | Cod sursa (job #2312611)
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
using namespace std;
struct Punct
{
double x, y;
};
const int N = 1001;
Punct *v;
int n;
int Cautare ( int st, int dr, Punct pct )
{
int m;
while(st <= dr)
{
m = ( st + dr ) / 2;
if(abs(pct.x - v[m].x) < 0.00001 && abs(pct.y - v[m].y) < 0.00001)
return 1;
if (abs(pct.x - v[m].x) < 0.00001)
{
if(pct.y < v[m].y )
dr = m - 1;
else
st = m + 1;
}
else
{
if( pct.x < v[m].x)
dr = m - 1;
else
st = m + 1;
}
}
return 0;
}
int Numar ()
{
int i, j, cnt = 0;
for( i = 1; i < n; i++ )
for(j = i + 1 ; j <= n; j++ )
{
Punct A, B, m;
m.x = (v[i].x + v[j].x) / 2;
m.y = (v[i].y + v[j].y) / 2;
A.x = m.x - v[j].y + m.y;
A.y = m.y + v[j].x - m.x;
B.x = m.x + v[j].y - m.y;
B.y = m.y - v[j].x + m.x;
if(Cautare(1, n, A) && Cautare(1, n, B))
++cnt;
}
return cnt/2;
}
bool cmp ( Punct A, Punct B)
{
if ( A.x < B.x || (A.x == B.x && A.y <= B.y))
return true;
return false;
}
int main()
{
ifstream in ("patrate3.in");
ofstream out ("patrate3.out");
int i;
in >> n;
v = new Punct [n + 1];
for ( i = 1; i <= n; i++ )
in >> v[i].x >> v[i].y;
sort( v + 1, v + n + 1, cmp );
out << Numar ();
delete ( v );
in.close();
out.close();
return 0;
}