Cod sursa(job #2129435)

Utilizator LizaSzabo Liza Liza Data 12 februarie 2018 20:34:11
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("trapez.in");
ofstream fout("trapez.out");
const int NMax=1005;
int N,Sol,k,nr;
double D[NMax*NMax];
struct punct
{
    double x,y;
};
punct A[NMax];



int main()
{
    fin>>N;
    fin>>A[1].x>>A[1].y;
    for(int i=2;i<=N;++i)
    {

        fin>>A[i].x>>A[i].y;
        for(int j=1;j<i;++j)
        {
            if((A[i].x!=A[j].x))
            {
              ++k;
            D[k]=(A[i].y-A[j].y)/(A[i].x-A[j].x);
            }
            else
            {
                ++k;
                D[k]=2000000000;
            }
        }
    }
    sort(D+1,D+k+1);
    for(int i=1;i<=k;++i)
    {
        int h=i-1;
        while(h>0 && D[h]==D[i])
        {
            Sol++;
            h--;
        }
    }
    fout<<Sol<<"\n";
    return 0;
}