Pagini recente » Cod sursa (job #671572) | Cod sursa (job #3240831) | Cod sursa (job #465893) | Cod sursa (job #1963315) | Cod sursa (job #14862)
Cod sursa(job #14862)
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define Nmax 1024
#define x first
#define y second
#define mp make_pair
const double eps = 0.000001;
int n;
pair<double, double> punct[Nmax];
void citeste()
{
int i;
double a, b;
scanf("%d\n", &n);
for (i=1; i<=n; ++i)
{
scanf("%lf %lf\n", &a, &b);
punct[i] = mp(a, b);
}
}
int cmp(pair<double, double> p1, pair<double, double> p2)
{
if (fabs(p1.x - p2.x) < eps && fabs(p1.y - p2.y) < eps)
return 0;
if (p1.x < p2.x + eps)
if (p1.x < p2.x - eps)
return 1;
else if (p1.y < p2.y - eps)
return 1;
return -1;
}
int cauta(pair<double, double> p)
{
int st = 1, dr = n, mij;
while (st <= dr)
{
mij = (st + dr) / 2;
if (cmp(p, punct[mij]) == 1)
dr = mij - 1;
else if (cmp(p, punct[mij]) == -1)
st = mij + 1;
else
return 1;
}
return 0;
}
void solve()
{
int i, j, sol = 0;
double x0, y0, dx, dy;
pair<double, double> p1, p2;
sort(punct+1, punct+n+1);
// for (i=1; i<=n; ++i)
// printf("%lf %lf\n", punct[i].x, punct[i].y);
for (i=1; i<=n; ++i)
for (j=i+1; j<=n; ++j)
{
x0 = (punct[i].x + punct[j].x) / 2;
y0 = (punct[i].y + punct[j].y) / 2;
dx = x0 - punct[i].x;
if (dx < 0) dx = -dx;
dy = y0 - punct[i].y;
if (dy < 0) dy = -dy;
if (punct[i].y < punct[j].y)
{
p1 = mp(x0 + dy, y0 - dx);
p2 = mp(x0 - dy, y0 + dx);
}
else
{
p1 = mp(x0 - dy, y0 - dx);
p2 = mp(x0 + dy, y0 + dx);
}
//printf("%lf %lf %lf %lf ----> %d\n", p1.x, p1.y, p2.x, p2.y, cauta(p1) && cauta(p2));
if (cauta(p1) && cauta(p2))
++sol;
}
printf("%d\n", sol / 2);
}
int main()
{
freopen("patrate3.in", "r", stdin);
freopen("patrate3.out", "w", stdout);
citeste();
solve();
return 0;
}