Cod sursa(job #1517911)

Utilizator preda.andreiPreda Andrei preda.andrei Data 4 noiembrie 2015 23:46:22
Problema Triang Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.16 kb
#include <iostream>
#include <stdio.h>
#include <cmath>

using namespace std;

struct Punct{
    double x, y;
    double dist;
};

Punct p[1501];

void inter(Punct &p1, Punct &p2){
    Punct paux=p1;
    p1=p2;
    p2=paux;
}

bool triunghi(Punct a, Punct b, Punct c){
    if(c.dist-a.dist==c.dist-b.dist && c.dist-a.dist==b.dist-a.dist)
        return true;
    return false;
}

int main()
{
    FILE *fin=fopen("triang.in", "r");
    FILE *fout=fopen("triang.out", "w");

    int n, x, k=0;

    fscanf(fin, "%d", &n);
    for(int i=1; i<=n; ++i){
        fscanf(fin, "%f%f", &p[i].x, &p[i].y);
        p[i].dist=sqrt(pow(p[i].x, 2)+pow(p[i].y, 2));
    }

    for(int i=1; i<n; ++i){
        x=i;
        for(int j=i+1; j<=n; ++j)
            if(p[j].dist<p[x].dist)
                x=j;
        if(i!=x)
            inter(p[i], p[x]);
    }

    for(int i=1; i<=n-2; ++i){
        for(int j=i+1; j<=n-1; ++j){
            for(int z=j+1; z<=n && p[z].dist-p[i].dist<=p[i].dist-p[j].dist; ++z)
                if(triunghi(p[i], p[j], p[z]))
                    k++;
        }
    }

    fprintf(fout, "%d", k);
    return 0;
}