Cod sursa(job #2002420)

Utilizator tziplea_stefanTiplea Stefan tziplea_stefan Data 19 iulie 2017 20:06:20
Problema Patrate 3 Scor 100
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2014, Anul I Marime 1.03 kb
#include <fstream>
#include <algorithm>
#include <set>
#define VAL 1005
#define x first
#define y second

using namespace std;

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

int N, i, j, ANS;
double dx, dy;
pair <double, double> P[VAL], pct1, pct2;

bool cmp(pair <double, double> A, pair<double, double> B)
{
    return (A.x<=B.x-0.00001 || A.x<B.x+0.00001 && A.y<=B.y-0.00001);
}

int main()
{
    fin >> N;
    for (i=1; i<=N; i++)
      fin >> P[i].x >> P[i].y;
    sort(P+1, P+N+1);
    for (i=1; i<=N; i++)
    {
        for (j=1; j<=N; j++)
        {
            if (P[j].x>P[i].x && P[j].y>=P[i].y)
            {
                dx=P[j].x-P[i].x;
                dy=P[j].y-P[i].y;
                pct1=make_pair(P[i].x+dy, P[i].y-dx);
                pct2=make_pair(P[j].x+dy, P[j].y-dx);
                if (binary_search(P+1, P+N+1, pct1, cmp)==true && binary_search(P+1, P+N+1, pct2, cmp)==true)
                  ANS++;
            }
        }
    }
    fout << ANS << '\n';
    fin.close();
    fout.close();
    return 0;
}