Cod sursa(job #1788084)

Utilizator alittlezzCazaciuc Valentin alittlezz Data 25 octombrie 2016 17:24:51
Problema Patrate 3 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
using namespace std;

struct thin{
    double x,y,l;
};

bool operator < (const thin &l, const thin &r) { return (l.x == r.x ? l.y < r.y : l.x < r.x); }
struct thing{
    double x,y;
}v[1005];

map <thin, int> m;

double dist(double x1, double y1, double x2, double y2){
    return (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
}

int main()
{
    freopen("patrate3.in", "r", stdin);
    freopen("patrate3.out", "w", stdout);
    int j,n,i;
    thin t;
    int ans = 0;
    scanf("%d", &n);
    for(i = 1;i <= n;i++){
        scanf("%lf %lf", &v[i].x, &v[i].y);
    }
    for(i = 1;i <= n;i++){
        for(j = i+1;j <= n;j++){
            t.x = (v[i].x + v[j].x)/2.0;
            t.y = (v[i].y + v[j].y)/2.0;
            t.l = dist(v[i].x, v[i].y, v[j].x, v[j].y);
            ans += m[t];
            m[t]++;
        }
    }
    printf("%d",ans);
    return 0;
}