Cod sursa(job #1284434)

Utilizator dragangabrielDragan Andrei Gabriel dragangabriel Data 6 decembrie 2014 15:30:55
Problema Patrate 3 Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.11 kb
#include<fstream>
#include<cstring>
#include<algorithm>
#include<unordered_map>
#include<cmath>
using namespace std;

unordered_map<int,int>mymap;
int n,i,j,k,rez;
const int constanta=10000;
int x[1005],y[1005];
long double vx,vy;

bool ok(int a,int b)
{
    unordered_map<int,int> :: iterator it;
    it=mymap.find(a);
    while (it!=mymap.end() && it->first==a )
    {
        if (it->second==b) return true;
        ++it;
    }
    return false;
}

ifstream f("patrate3.in");
ofstream g("patrate3.out");
int main()   //adun 10 000
{
    f>>n;
    for(i=1;i<=n;i++)
    {
        f>>vx>>vy;
        vx*=constanta;
        x[i]=vx+(constanta*10);
        vy*=constanta;
        y[i]=vy+(constanta*10);
        mymap[(int)x[i]]=(int)y[i];
    }
    for(i=1;i<=n;i++)
        for(j=1;j<i;j++)
        {
            int x1temp=x[i]+y[i]-y[j];
            int y1temp=x[j]+y[i]-x[i];
            int x2temp=x[j]+y[i]-y[j];
            int y2temp=x[j]+y[j]-x[i];
            if (ok(x1temp,y1temp) && ok(x2temp,y2temp))
                rez++;
        }
    g<<rez/2<<"\n";
    return 0;
}