Cod sursa(job #806330)

Utilizator mihai_tMihai Teletin mihai_t Data 2 noiembrie 2012 16:49:11
Problema Trapez Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.22 kb
#include <fstream>
#include <iostream>
#include <algorithm>
using namespace std;

int n,m2=0;
long m,c=0,x,y;
struct punct
{
    int x,y;
};
punct a[1000];
long double b[500500];
int s[1000];
void cit()
{
    ifstream f;
    f.open("trapez.in");
    f>>n;
    for (int i=1;i<=n;i++)
    {
        f>>a[i].x>>a[i].y;
    }
    f.close();
}
void panta()
{
    m=0;
    for (int i=1;i<=n;i++)
        for (int j=i+1;j<=n;j++)
        {
                if (a[i].x!=a[j].x)
                {
                m++;
                if (a[i].y-a[j].y==0) b[m]=0;
                else
                b[m]=(double)((a[i].y-a[j].y))/(a[i].x-a[j].x);
                }
                else
                {
                    c++;
                }
        }
    c=c*(c-1)/2;
}
long cate()
{
    int i=1;int j;
    while (i<=m)
    {
            j=i+1;
            while (b[i]==b[j])
            {
                c++;
                j++;
            }
            i=j;
    }
    return c;
}
int main()
{
    cit();
    panta();
    sort(b+1,b+m+1);
    for (int i=1;i<=m;i++) cout<<b[i]<<" ";
    ofstream g;
    g.open("trapez.out");
    g<<cate();
    g.close();
    return 0;
}