Cod sursa(job #1279596)

Utilizator RazecBotez Cezar Razec Data 30 noiembrie 2014 16:58:55
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include<cstdio>
#include<algorithm>
using namespace std;
const int NMAX = 1005;
const int INF = 1<<30;
//const double eps = 0.000000000001;
int N,i,j,A,B,C,SOL,Cnt; double M[NMAX*NMAX];
struct Point {int X,Y;} P[NMAX];
int main()
{
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);
    scanf("%d",&N);
    for(i=1;i<=N;i++)
    {
        scanf("%d",&P[i].X);
        scanf("%d",&P[i].Y);
    }
    for(i=1;i<N;i++)
        for(j=i+1;j<=N;j++)
        {
            A=P[j].Y-P[i].Y;
            B=P[j].X-P[i].X;
            if(!B) {M[++C]=INF; continue;}
            M[++C]=(double)A/B;
        }
    sort(M+1,M+C+1); Cnt=1;
    for(i=2;i<=C;i++)
    {
        if(M[i]-M[i-1]==0) Cnt++;
        else {SOL+=(Cnt*(Cnt-1))/2; Cnt=1;}
    }
    printf("%d\n",SOL);
    return 0;
}