Cod sursa(job #1083259)

Utilizator WyvernFMI Stanescu Leonard Wyvern Data 15 ianuarie 2014 19:50:53
Problema Patrate 3 Scor 0
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2013 Marime 1.12 kb
#include <algorithm>
#include <fstream>
using namespace std;
ifstream fi("patrate3.in");
ofstream fo("patrate3.out");
#define EPS 1e-5
#define less(a, b) ((a) < (b)-EPS)
#define abs(x) ((x) < 0 ? -(x) : (x))
#define eq(a, b) (abs((a)-(b)) < EPS)
#define x first
#define y second
#define mp make_pair
typedef pair<double,double>point;
int N,Res,i,j;
double x1,y1,x2,y2,x3,y3,x4,y4,a,b,mx,my;
point P[1024],*p;
inline bool cmp(point a,point b){return less(a.x,b.x)||(eq(a.x,b.x)&&less(a.y,b.y));}
int main() {
    fi>>N;
    for (i=0;i<N;i++)
        fi>>P[i].x>>P[i].y;
    sort(P,P+N,cmp);
    for (i=0;i<N;i++)
        for (j=i+1;j<N;j++) {
            x1=P[i].x,y1=P[i].y,x2=P[j].x,y2=P[j].y;
            mx=(x1+x2)*0.5;my=(y1+y2)*0.5;
            a=y1-y2;b=x2-x1;
            x3=a*0.5+mx;y3=b*0.5+my;
            x4 =-a*0.5+mx;y4=-b*0.5+my;
            p=lower_bound(P,P+N,mp(x3,y3),cmp);
            if (!eq(p->x,x3)||!eq(p->y,y3)) continue;
            p=lower_bound(P,P+N,mp(x4,y4),cmp);
            if (!eq(p->x,x4)||!eq(p->y,y4)) continue;
            Res++;
        }
    fo<<Res/2;
    return 0;
}