Pagini recente » Cod sursa (job #588264) | Cod sursa (job #2917220) | Cod sursa (job #2902782) | Cod sursa (job #2446365) | Cod sursa (job #2474377)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("patrate3.in");
ofstream g("patrate3.out");
const double EPS = 1e-5;
struct punct
{
double x, y;
};
int N;
punct P[1001];
int egal(double a, double b)
{
double d = a - b;
if(d < -EPS)
return -1;
if(d > +EPS)
return 1;
return 0;
}
int egal(const punct &A, const punct &B)
{
int ex = egal(A.x, B.x);
int ey = egal(A.y, B.y);
if(ex == 0)
return ey;
return ex;
}
bool cmp(const punct &A, const punct&B)
{
return egal(A, B) < 0;
}
bool cautbin(const punct &A)
{
int st = 1, dr = N;
while(st <= dr)
{
int m = (st + dr) / 2;
int e = egal(P[m], A);
if(e == 0)
return 1;
if(e == 1)
dr = m - 1;
else
st = m + 1;
}
return 0;
}
void solve()
{
int nrp = 0;
for(int i = 1; i < N; i++)
for(int j = i + 1; j <= N; j++)
{
punct M, A, B;
M.x = (P[i].x + P[j].x) / 2;
M.y = (P[i].y + P[j].y) / 2;
A.x = M.x - P[j].y + M.y;
A.y = M.y + P[j].x - M.x;
B.x = M.x + P[j].y - M.y;
B.y = M.y - P[j].x + M.x;
if(cautbin(A) && cautbin(B))
nrp++;
}
g << nrp / 2;
}
int main()
{
f >> N;
for(int i = 1; i <= N; i++)
f >> P[i].x >> P[i].y;
sort(P + 1, P + N + 1, cmp);
solve();
return 0;
}