Cod sursa(job #2237802)

Utilizator ipop20Ioana Popescu ipop20 Data 3 septembrie 2018 09:56:18
Problema Trapez Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <fstream>
#include <algorithm>

using namespace std;
const double eps=10e-6;
ifstream fin ("trapez.in");
ofstream fout ("trapez.out");
const int NMAX=1000;
const int PMAX=500000;
struct POINT
{
    int x,y;
};
float panta (POINT P1,POINT P2)
{
   return (P2.y-P1.y)/(P2.x-P1.x);
};
POINT p[NMAX+5];
float pan[PMAX];
int main()
{
    int N,tx,ty,i,j,k,l,ans=0;
    fin>>N;
    for(i=1;i<=N;i++)
    {
       fin>>tx>>ty;
       p[i].x=tx;p[i].y=ty;
    }
    k=0;
    for(i=1;i<N;i++)
    {
       for(j=i+1;i<=N;i++)
       {
            k++;
            pan[k]=panta(p[i],p[j]);
       }
    }
    sort(pan+1,pan+k+1);
    l=1;
    for(i=2;i<=k;i++)
    {
        if(fabs(pan[i]-pan[i-1])<eps)
            l++;
        else
        {
            ans+=1LL*l*(l-1);
            l=1;
        }
    }
    ans+=1LL*l*(l-1);
    fout<<ans;
    fin.close();fout.close();
    return 0;
}