Cod sursa(job #2125860)

Utilizator boboomBoomerang boboom Data 8 februarie 2018 19:56:04
Problema Patrate 3 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <fstream>
#include <algorithm>
#define nmax 5002
#define qmax 1002
using namespace std;
ifstream fin("patrate3.in");
ofstream fout("patrate3.out");

struct punct{
    double d,s;
};

punct v[nmax*nmax*2];

double x[qmax];
double y[qmax];

bool cmp(punct A,punct B)
{
    if(A.d==B.d)
        return A.s<B.s;
    return A.d<B.d;
}

int main()
{
    int n;
    fin>>n;
    int con=0;
    for(int i=1;i<=n;i++)
    {
        fin>>x[i]>>y[i];
        for(int j=1;j<i;j++)
        {
            con++;
            v[con].d=(double)(x[i]+x[j])/2.;
            v[con].s=(double)(y[i]+y[j])/2.;
        }
    }
    sort(v+1,v+con+1,cmp);
    int k=1;
    int contor=0;
    while(k<=con)
    {
        int c=0;
        while(v[k].d==v[k+1].d&&v[k].s==v[k+1].s)
        {
            c++;
            k++;
        }
        k++;
        contor+=(c*(c+1))/2;
    }
    fout<<contor;
    return 0;
}