Cod sursa(job #984037)

Utilizator mlupseLupse-Turpan Mircea mlupse Data 13 august 2013 13:33:31
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("trapez.in");
ofstream g("trapez.out");
pair<int,int> Array[1002];
long double Pant[1000002];
int N,k;
long long Result;
void Read()
{
    f>>N;
    int i;
    for(i=1;i<=N;i++)
        f>>Array[i].first>>Array[i].second;
}
void Count_Pants()
{
    int i,j;
    for(i=1;i<=N;i++)
        for(j=i+1;j<=N;j++)
            Pant[++k]=(long double)(Array[i].first-Array[j].first)/(long double)(Array[i].second-Array[j].second);
    sort(Pant+1,Pant+k+1);
}
void Solve()
{
    int i,counter=1;
    for(i=2;i<=k;i++)
    {
        if(Pant[i]==Pant[i-1])
            counter++;
        else
        {
            Result+=counter*(counter-1)/2;
            counter=1;
        }
    }
    g<<Result<<"\n";
}
int main()
{
    Read();
    Count_Pants();
    Solve();
    return 0;
}