Cod sursa(job #1047792)

Utilizator dan.ghitaDan Ghita dan.ghita Data 4 decembrie 2013 21:28:14
Problema Patrate 3 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.15 kb
#include <iostream>
#include <fstream>
#include <unordered_set>
#include <vector>
#include<algorithm>
using namespace std;
ifstream f("patrate3.in");
ofstream g("patrate3.out");
int n, k;
double a, b;
pair<double, double> A,B;
class pair_h{
public:
    long operator()(const pair<double, double> &k) const{
        return (int)(k.first * 100 + k.second)%666013;
    }
};
unordered_set< pair<double, double>, pair_h > h;
vector< pair<double, double> > v;
vector< pair<double, double> >::iterator it, jt;

int main()
{
    f>>n;
    while(n--){
        f>>a>>b;
        h.insert(make_pair(a,b));
        v.push_back(make_pair(a,b));
    }
    sort(v.begin(), v.end());
    for(it=v.begin(); it!=v.end(); ++it)
    for(jt=it+1; jt!=v.end(); ++jt){
        A=make_pair(it->first+it->second-jt->second,it->second+jt->first-it->first);
        B=make_pair(jt->first+it->second-jt->second,jt->second+jt->first-it->first);
//        cout<<A.first<<' '<<A.second<<' '<<B.first<<' '<<B.second;
        if(h.find(A)!=h.end()&&h.find(B)!=h.end()) k++;//, cout<<" <---\n";
        //else cout<<" nu e in hash!\n";

    }
    g<<k/2;


    return 0;
}