Cod sursa(job #1736605)

Utilizator VladTiberiuMihailescu Vlad Tiberiu VladTiberiu Data 2 august 2016 11:45:55
Problema Trapez Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <bits/stdc++.h>

#define NMax 1005
using namespace std;
ifstream f("trapez.in");
ofstream g("trapez.out");
struct drepte{
    float a;
    bool off;
};

drepte dr[NMax * NMax];
int n,nr,ans;
float x[NMax],y[NMax];


bool cmp(drepte x, drepte y){
    if(x.off == 0 && y.off == 1)
        return 1;
    if(x.a > y.a)
        return 1;
    return 0;
}
int main()
{
    f >> n;
    for(int i = 1; i <= n; ++i){
        f >> x[i] >> y[i];
    }
    for(int i = 1; i <= n; ++i){

        for(int j = i + 1; j <= n; ++j){
            if(x[i] - x[j] == 0){
                dr[++nr].off = 1;
            }else{
                dr[++nr].a = (y[i] - y[j]) / (x[i] - x[j]);
            }
        }
    }
    sort(dr + 1, dr + 1 + nr, cmp);
    for(int i = 2; i <= nr; ++i){
        if(dr[i].a == dr[i - 1].a)
            ++ans;
    }
    g << ans << '\n';
    return 0;
}