Cod sursa(job #1360384)

Utilizator bidaman98catyTunea Catalin bidaman98caty Data 25 februarie 2015 14:09:03
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <fstream>
#include <cmath>
#include <algorithm>

const int inf = 0x3f3f3f3f;

using namespace std;

int main()
{
    ifstream f("trapez.in");
    ofstream g("trapez.out");
    int q,n,i,j,k=1,m,c=0,nr=0;
    f>>n;
    q=n*(n+1)/2;
    double a[q];
    struct L {int x,y;};
    L p[n+1];
    for(i=1;i<=n;i++)
          f>>p[i].x>>p[i].y;
    for(i=1;i<=n-1;i++)
        for(j=i+1;j<=n;j++)
              if(p[i].y==p[j].y)
                        a[++nr]=inf;
                        else
                        {
                           a[++nr]= (double)(p[j].x-p[i].x) / (p[j].y-p[i].y);
                        }
    sort(a+1,a+nr+1);
    for( int i = 2; i <= nr; i++)
    {
        if( a[i] == a[i-1] )
            k++;
            else
             {
               c += k * ( k - 1) / 2;
               k = 1;
             }
    }
    c += k * ( k - 1) / 2;
    g<<c;
    return 0;
}