Pagini recente » Cod sursa (job #1087383) | Cod sursa (job #2298913) | Cod sursa (job #1257037) | Cod sursa (job #1573291) | Cod sursa (job #97805)
Cod sursa(job #97805)
#include <stdio.h>
#include <stdlib.h>
#include <fstream.h>
int contor, n, ord[1000];
typedef struct
{
float x, y;
} punct;
punct a[1000], b[1000];
int cmp(const void *a, const void *c)
{
int x=*(int *)a, y=*(int *)c;
if (b[x].x == b[y].x) return b[x].y-b[y].y;
else return b[x].x-b[y].x;
}
void citire()
{
ifstream in("patrate3.in");
freopen("patrate3.out","w",stdout);
in>>n;
int i;
for (i=1; i<=n; i++)
{
in>>b[i].x>>b[i].y;
ord[i]=i;
}
}
int caut(int x, int y, int p, int u)
{
int m;
int xx, yy;
m=(p+u)/2;
while (p<=u)
{
xx = (int) a[m].x*10000;
yy = (int) a[m].y*10000;
if (xx==x && yy==y) return 1;
else if ((xx==x && yy<y) || (xx<x)) {p=m+1; m=(p+u)/2;}
else if ((xx==x && yy>y) || (xx>x)) {u=m-1; m=(p+u)/2;}
}
return 0;
}
float ab(float x)
{
if (x<0) return -x;
return x;
}
int main()
{
citire();
int i, j;
qsort(ord,n+1,sizeof(int),cmp);
for (i=1; i<=n; i++) a[i]=b[ord[i]];
float mijx, mijy, x3, x4, y3, y4, dx, dy;
for (i=1; i<=n-3; i++)
for (j=i+1; j<=n-2; j++)
{
mijx = (float) (a[i].x+a[j].x)/2;
mijy = (float) (a[i].y+a[j].y)/2;
dx = ab(mijx - a[i].x);
dy = ab(mijy - a[i].y);
if (a[i].y < a[j].y)
{
x3 = mijx + dy;
y3 = mijy - dx;
x4 = mijx - dy;
y4 = mijy + dx;
}
else
{
x3 = mijx - dy;
y3 = mijy - dx;
x4 = mijx + dy;
y4 = mijy + dx;
}
if (caut((int)x3*10000, (int)y3*10000, 1, n) && caut((int)x4*10000, (int)y4*10000, 1, n)) contor++;
}
printf("%d\n",contor);
return 0;
}