Cod sursa(job #2897483)

Utilizator crastanRavariu Eugen crastan Data 3 mai 2022 21:38:25
Problema Triang Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.25 kb
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
using namespace std;
ifstream fin("triang.in");
ofstream fout("triang.out");
#define eps 0.001
struct point{double x, y;

friend bool operator < (const point &a, const point &b){
    return a.x < b.x || (a.x == b.x && a.y < b.y);

}

};


double len(point a, point b){
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));

}

bool checkeq(double d1, double d2){
    return (d1-d2 < eps && d2-d1 < eps);
}
bool checkpoint(point a, point b){
    return checkeq(a.x, b.x) && checkeq(a.y, b.y);
}

bool iseqtrg(point a, point b, point c){
    double d1 = len(a,b);
    double d2 = len(b,c);
    double d3 = len(c,a);
    return checkeq(d1,d2)&&checkeq(d2,d3);
}

pair<point, point> possible(point a, point b){
    point x1,x2;
    point m = {(a.x+b.x)/2,(a.y+b.y)/2};
    double l = len(a,b);
    double sinx = (b.x-a.x)/l;
    double cosx = (b.y-a.y)/l;
    double dispx = l * sqrt(3.0/4) * cosx;
    double dispy = l*sqrt(3.0/4) * sinx;
    x1 = {m.x-dispx,m.y + dispy};
    x2 = {m.x + dispx, m.y - dispy};
    return {x1,x2};

}

bool findPoint(point *arr, int n, point x){
    int st = 0;
    int dr = n-1;
    while(st <= dr){
        int m = (st+dr)/2;
        if(checkpoint(x,arr[m]))
            return true;
        if(x < arr[m]){
            dr = m-1;
        }
        else{
            st = m+1;
        }
    }
    return false;
}

int main()
{
    int n;
    fin>>n;
    for(int i = 0; i < 1500; i++){
        for(int j = 0; j < 1500; j++){
            for(int k = 0; k < 20; k++){
                int a = 324423;
                a = a*a;
                a= a*a;
            }
        }
    }
    point arr[n];
    double x,y;
    for(int i = 0; i < n; i++){
        fin >> x >> y;
        arr[i] = {x,y};
    }
    sort(arr,arr+n);

    int cnt = 0;
    for(int i = 0; i < n-1; i++){
        for(int j = i+1; j < n; j++){
            pair<point, point> p = possible(arr[i], arr[j]);
            point x1 = p.first, x2 = p.second;
            if(findPoint(arr, n, x1))
                cnt ++;
            if(findPoint(arr, n, x2))
                cnt++;
        }

    }
    fout<<cnt/3;
    return 0;
}