Cod sursa(job #2348446)

Utilizator alexradu04Radu Alexandru alexradu04 Data 19 februarie 2019 18:43:48
Problema Patrate 3 Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.72 kb
#include <fstream>
#include <algorithm>
#include <vector>

using namespace std;

ifstream cin("patrate3.in");
ofstream cout("patrate3.out");

int sign(int a) {
    if(a < 0) return -1;
    else    return 1;
}

struct POINT {
    long long int x, y;
};

bool cmp(POINT a, POINT b) {
    if(a.x == b.x)
        return a.y > b.y;
    return a.x > b.x;
}

bool operator ==(POINT a, POINT b) {
    return a.x == b.x && a.y == b.y;
}

vector< POINT > v;

bool pointexists(POINT a) {
    if(*(lower_bound(v.begin(), v.end(), a, cmp)) == a)
        return 1;
    return 0;
}

bool exists(POINT a, POINT b) {
    long long int dx, dy;
    dx = a.x - b.x;
    dy = a.y - b.y;
    
    POINT tmp;
    tmp.x = b.x + dy;
    tmp.y = b.y - dx;
    if(!pointexists(tmp))
        return 0;
    tmp.x += dx;
    tmp.y += dy;
    if(!pointexists(tmp))
        return 0;
    return 1;
}

int main()
{
    int n;
    cin >> n;
    
    long long int tmp, tmpf;
    char c;
    
    POINT cng;
    
    for(int i = 0; i < n; i++) {
        cin >> tmp >> c >> tmpf;
        cng.x = tmp*10000 + sign(tmp)*tmpf;
        cin >> tmp >> c >> tmpf;
        cng.y = tmp*10000 + sign(tmp)*tmpf;
        v.push_back(cng);
    }
    
    sort(v.begin(), v.end(), cmp);
    
    //cout << pointexists(cng) << endl;
    
    POINT a, b;
    int sum = 0;
    for(int i = 0; i < n; i++) {
        a = v[i];
        for(int j = i+1; j < n; j++) {
            b = v[j];
            if(exists(a, b)) {
                sum++;
                //cout << a.x << " " << a.y << endl;     
                //cout << b.x << " " << b.y << endl;     
            }
        }
    }
    
    sum /= 2;
    cout << sum;
}