Cod sursa(job #687664)

Utilizator PetcuIoanPetcu Ioan Vlad PetcuIoan Data 22 februarie 2012 17:44:50
Problema Trapez Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.01 kb
#include<stdio.h>
#include<assert.h>
#include<math.h>

#include<algorithm>

using namespace std;

const double keps = 0.0001;
const int kmaxn = 1005;
int n, sol, px[kmaxn], py[kmaxn];
double angles[kmaxn * kmaxn];

void read(){
    assert(freopen("trapez.in","r",stdin)!=NULL);
    scanf("%d",&n);
    int i;
    for(i = 1; i <= n; ++i)
        scanf("%d%d",&px[i] ,&py[i]);
}

int modul(int x){
    if(x > 0)
        return x;
    return -x;
}

void solve(){
    int i, j, u = 0, curent = 0;
    for(i = 1; i <= n; ++i)
        for(j = i + 1; j <= n; ++j)
            angles[++u] = (double)((double)modul(px[i] - px[j])) / ((double)modul(py[i] - py[j]));
    sort(angles + 1, angles + u + 1);
    for(i = 1; i <= u; ++i)
        if(angles[i] - angles[i - 1] < keps){
            ++curent;
            sol += curent;
        }
        else
            curent = 0;
    sol /= 2;
}

void write(){
    assert(freopen("trapez.out","w",stdout)!=NULL);
    printf("%d",sol);
}

int main(){
    read();
    solve();
    write();
    return 0;
}