Cod sursa(job #2895770)

Utilizator crastanRavariu Eugen crastan Data 29 aprilie 2022 14:25:48
Problema Triang Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.55 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 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);
}

struct pr{double len;int id;

friend bool operator < (const pr &a, const pr &b){
    return a.len < b.len || (a.len == b.len && a.id < b.id);

}

};

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};
    }
    pr v[n];
    int cnt = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            v[j] = {len(arr[i],arr[j]),j};
        }
        sort(v,v+n);
        for(int j = 1; j < n; j++){
            cnt += iseqtrg(arr[i], arr[v[j-1].id], arr[v[j].id]);
        }
    }
    fout<<cnt/3;
    return 0;
}