Cod sursa(job #2236573)

Utilizator ovidiuz98Zamfir Ovidiu ovidiuz98 Data 29 august 2018 23:16:03
Problema Patrate 3 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.34 kb
#include <fstream>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#define MOD 100013
#define DIM 1005*502
#define eps 0.00001
 
using namespace std;
 
ifstream fin("patrate3.in");
ofstream fout("patrate3.out");
struct point{
    double x, y;
}P[1005];

long long int squaredist(point a,point b){
    return 1LL*(a.x-b.x)*(a.x-b.x)+1LL*(a.y-b.y)*(a.y-b.y);
}
int Area(point p1,point p2,point p3){
    return (p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y);
}
vector <point> H[MOD];
int N,nr;
int SquaresCount;

int cmp(point A, point B){
    if(A.x < B.x)
        return 1;
    if(A.x == B.x && A.y < B.y)
        return 1;
    return 0;
}

int modulo(int number){
    int ans = number % MOD;
    if(ans < 0)
        ans += MOD;
    return ans;
}

int main(){
    fin>>N;
    
    for(int i = 1; i <= N; i ++){
        fin >> P[i].x >> P[i].y;
        int key = P[i].x * 10000;
        key = modulo(key);
        H[key].push_back(P[i]);
    }

    sort(P + 1, P + N + 1, cmp);

    for(int i = 1; i <= N; i ++)
        for(int j = 1; j <= N; j ++)
            if(i != j){

            point firstPoint, secondPoint;

            double a = P[j].x - P[i].x;
            double b = P[j].y - P[i].y;

            firstPoint.x = P[i].x - b;
            firstPoint.y = P[i].y + a;

            a = P[i].x - P[j].x;
            b = P[i].y - P[j].y;

            secondPoint.x = P[j].x + b;
            secondPoint.y = P[j].y - a;

            int key1 = firstPoint.x * 10000;
            key1 = modulo(key1);
            int key2 = secondPoint.x * 10000;
            key2 = modulo(key2);

            int found1 = 0, found2 = 0;

            //fout << firstPoint.x << " " << firstPoint.y << "\n";
            for(std::vector<point>::iterator it=H[key1].begin();it!=H[key1].end(); it ++)
                if(abs(it->x - firstPoint.x) < eps && abs(it->y - firstPoint.y) < eps){
                    found1 = 1;
                    break;
                }

            if(!found1)
                continue;

            for(std::vector<point>::iterator it=H[key2].begin();it!=H[key2].end(); it ++)
                if(abs(it->x - secondPoint.x) < eps && abs(it->y - secondPoint.y) < eps){
                    found2 = 1;
                    break;
                }

            if(found2)
                SquaresCount ++;

        }

    fout << SquaresCount / 2 << "\n";
    
}