Cod sursa(job #2096471)

Utilizator Ioana_AndreeaCristescu Ioana Ioana_Andreea Data 29 decembrie 2017 12:00:26
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <fstream>
#include <algorithm>
using namespace std;

ifstream fin ("trapez.in");
ofstream fout ("trapez.out");
int n, x, y, k;
int i, j;
const int oo=2000000005;
double numarator, numitor;
double M[1000005];
int contor=1, S;
struct Punct
{
    int x, y;
} P[1005];

int main()
{
    fin>>n;
    for (i=1; i<=n; i++)
        fin>>P[i].x>>P[i].y;
    for (i=1; i<=n; i++)
        for (j=i+1; j<=n; j++)
        {
           k++;
           numarator = P[i].y - P[j].y;
           numitor = P[i].x - P[j].x;
           if (numitor==0)
               M[k]=oo;
           else
               M[k]=double(numarator/numitor);
        }
    sort (M+1, M+k+1);
    for (i=2; i<=k; i++)
    {
        if (M[i-1]==M[i])
            contor++;
        else
        {
            S=S+(contor-1)*contor/2;
            contor=1;
        }
    }
    fout<<S<<"\n";
    return 0;
}