Cod sursa(job #1017633)

Utilizator Iustin_BulimarFMI Iustin Bulimar Iustin_Bulimar Data 28 octombrie 2013 00:22:33
Problema Trapez Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.22 kb
#include <fstream>

using namespace std;

ifstream cin("trapez.in");
ofstream cout("trapez.out");

short n, i, j;
int k, t;
int x[1001], y[1001], a[600001], b[600001];
void qsort(int a[], int b[], int st, int dr)
{
      int i=st, j=dr;
      int piv = a[(st+dr)/2];
      while (i <= j)
      {
            while (a[i] < piv) i++;
            while (a[j] > piv) j--;
            if (i <= j)
            {
                  swap(a[i],a[j]);
                  swap(b[i],b[j]);
                  i++;
                  j--;
            }
      }
      if (st < j) qsort(a, b, st, j);
      if (i < dr) qsort(a, b, i, dr);
}
int main()
{
    cin>>n;
    for(i=1; i<=n; i++) cin>>x[i]>>y[i];
    for(i=1; i<n; i++)
        for(j=i+1; j<=n; j++)
        {
            ++k;
            a[k]=y[i]-y[j];
            b[k]=x[i]-x[j];
        }
    for(i=1; i<k; i++)
        for(j=i+1; j<=k; j++)
            if(a[i]==0 && a[j]==0) t++;
            else if(b[i]==0 && b[j]==0) t++;
    qsort(a, b, 1, k);
    for(i=1; i<k; i++)
        for(j=i+1; j<=k; j++)
            if(a[i] && a[j] && b[i] && b[j])
                if(a[j]%a[i]==0 && b[j]%b[i]==0 && a[j]/a[i]==b[j]/b[i]) t++;
    cout<<t;
    return 0;
}