Cod sursa(job #2002352)

Utilizator tziplea_stefanTiplea Stefan tziplea_stefan Data 19 iulie 2017 15:15:11
Problema Patrate 3 Scor 0
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2013 Marime 0.93 kb
#include <fstream>
#include <algorithm>
#include <set>
#define VAL 1005
#define F first
#define S second

using namespace std;

ifstream fin("patrate3.in");
ofstream fout("patrate3.out");

int N, ans, i, j;
double H, L;
pair <double, double> pct, P1, P2;
pair <double, double> P[VAL];
set < pair <double, double> > S;

int main()
{
    fin >> N;
    for (i=1; i<=N; i++)
    {
        fin >> P[i].F >> P[i].S;
        S.insert(P[i]);
    }
    sort(P+1, P+N+1);
    for (i=1; i<N; i++)
    {
        for (j=i+1; j<=N; j++)
        {
            pct.F=(P[i].F+P[j].F) / 2;
            pct.S=(P[i].S+P[j].S) / 2;
            H=pct.F-P[i].F;
            L=pct.S-P[i].S;
            P1.F=pct.F-L;
            P1.S=pct.S+H;
            P2.F=pct.F+L;
            P2.S=pct.S-H;
            if (S.find(P1)!=S.end() && S.find(P2)!=S.end())
              ans++;
        }
    }
    fout << ans / 2 << '\n';
    fin.close();
    fout.close();
    return 0;
}