Cod sursa(job #476715)

Utilizator dicu_dariaDaria Dicu dicu_daria Data 12 august 2010 11:18:34
Problema Trapez Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.14 kb
#include <fstream>
#include <algorithm>
using namespace std;
typedef struct{
  int x, y;
} unghi;
unghi panta[100001];
int i,j,x[1001],y[1001],n,k,total;
bool ok;
bool cmp(unghi aa,unghi bb)
{
    double a,b;
     if(!aa.y) a=200000000; else
      a=(double)aa.x/aa.y;
      if(!bb.y) b=200000000; else
      b=(double)bb.x/bb.y;
    return(a<b);
}
int main()
{
    double a,b;
    ifstream fi("trapez.in");
    ofstream fo("trapez.out");
    fi>>n;
    for(i=1;i<=n;i++)
      fi>>x[i]>>y[i];
    k=0;
    for(i=1;i<=n;i++)
      for(j=i+1;j<=n;j++)
        {
          panta[++k].x=x[i]-x[j];
          panta[k].y=y[i]-y[j];

        }
    sort(panta+1,panta+k+1,cmp);
    n=0; total=0; ok=0;
    for(i=2;i<=k;i++)
    {
      if(panta[i].y) {
      a=(double)panta[i].x/panta[i].y;
      if(panta[i-1].y) b=(double)panta[i-1].x/panta[i-1].y;
      } else if((!panta[i-1].y)&&(!panta[i].y)) { a=1; b=1; }
      if(a==b) { n++; ok=1; }else if(ok)
      {
        total+=(n*(n+1))/2;
        n=0;
        ok=0;
      }
    }
    if(ok)   total+=(n*(n+1))/2;
    fo<<total<<"\n";
    fo.close();
    return 0;
}