Cod sursa(job #1282147)

Utilizator deresurobertoFMI - Deresu Roberto deresuroberto Data 3 decembrie 2014 23:17:44
Problema Patrate 3 Scor 45
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.45 kb
//Deresu Roberto - FMI
//Re :)
#include<fstream>
#include<algorithm>
#include<map>
#define nx 100000
using namespace std;
int n,rez;

struct punct
{
    int x,y;
}a[100007];

map<int,int>mymap;
map<int,int> :: iterator it;

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

int cmp(punct a, punct b)
{
    if(a.x < b.x || (a.x == b.x && a.y < b.y)) return 1;
    return 0;
}

int cauta(int x, int y)
{
    it = mymap.find(x);

    while(it != mymap.end() && it->first == x)
    {
        if(it->second == y) return 1;
        it++;
    }

    return 0;
}

int numar()
{
    double y;

    fin>>y;
    y *= nx;

    int x = y;

    if(x >= 0)
    {
        if(x%10 == 9) x = x/10+1;
                 else x = x/10;
    }
    else
    {
        if(-x%10 == 9) x = x/10-1;
                  else x = x/10;
    }

    return 2*x;
}

int main()
{
    fin>>n;

    for(int i=1;i<=n;i++)
    {
        a[i].x = numar();
        a[i].y = numar();
        mymap.insert(pair<int,int>(a[i].x,a[i].y));
    }

    sort(a+1,a+n+1,cmp);

    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
        {
            int x3,y3,x4,y4;

            x3 = a[i].x+a[i].y-a[j].y;
            y3 = a[i].y+a[j].x-a[i].x;
            x4 = a[i].y+a[j].x-a[j].y;
            y4 = a[j].x+a[j].y-a[i].x;

            if(cauta(x3,y3) && cauta(x4,y4)) rez++;
        }

    fout<<rez/2<<'\n';

    return 0;
}