Cod sursa(job #1284500)

Utilizator dragangabrielDragan Andrei Gabriel dragangabriel Data 6 decembrie 2014 16:07:33
Problema Patrate 3 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1 kb
#include<fstream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;

vector<pair<int,int> >v;
int n,i,j,k,sol;
long double x[1005],y[1005];

ifstream f("patrate3.in");
ofstream g("patrate3.out");

int main()
{
    f>>n;
    for(i=1;i<=n;i++)
    {
        f>>x[i]>>y[i];
        x[i]*=10000;
        y[i]*=10000;
        if (x[i]<0) x[i]-=0.5;else x[i]+=0.5;
        if (y[i]<0) y[i]-=0.5;else y[i]+=0.5;
        v.push_back(make_pair(x[i],y[i]));
    }
    sort(v.begin(),v.end());
    for(i=0;i<n-1;i++)
        for(j=i+1;j<n;j++)
        {
           pair<int,int>px,py;
           px.first=v[i].first+v[i].second-v[j].second;
           px.second=v[j].first+v[i].second-v[i].first;
           py.first=v[j].first+v[i].second-v[j].second;
           py.second=v[j].first+v[j].second-v[i].first;
           if (binary_search(v.begin(),v.end(),px) && binary_search(v.begin(),v.end(),py))
                sol++;
        }
    g<<sol/2<<"\n";
}