Cod sursa(job #1082993)

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