Cod sursa(job #1729274)

Utilizator victor.manoliu15Victor Manoliu victor.manoliu15 Data 14 iulie 2016 15:31:10
Problema Trapez Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 kb
#include<fstream>
#include<algorithm>
using namespace std;
ifstream f("trapez.in");
ofstream g("trapez.out");
int solutie,z=1,nr,i,j,n,INFINIT=200002;
struct trapez
{
    int x;
    int y;

}v[10000];
double panta[100005];
int main()
{
    f>>n;

    for(i=1; i<=n; i++)
    {
        f>>v[i].x>>v[i].y;
    }

    for(i=1; i<=n; i++)
        for(j=i+1; j<=n; j++)
        if(v[i].x==v[j].x)
    {
        panta[++nr]=INFINIT;
    }
    else
    {
        panta[++nr]=double(v[i].y-v[j].y)/(v[j].x-v[i].x);
    }

    sort(panta+1,panta+nr+1);


    for(i=2; i<=nr; i++)
    {
        if(panta[i]==panta[i-1])
        {
            z++;
        }
        else
        {
            solutie=solutie+z*(z-1)/2;
            z=1;
        }
    }

    solutie=solutie+z*(z-1)/2;

    g<<solutie;

    f.close();
    g.close();

    return 0;
}