Cod sursa(job #1981436)

Utilizator ardutgamerAndrei Bancila ardutgamer Data 15 mai 2017 18:37:24
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.46 kb
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>

using namespace std;

const double eps = 1.e-14;
const double INF = 2.e9;
struct POINT{
int x , y;
};

double dist(POINT A ,POINT B)
{
    return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}

bool vertical(POINT A, POINT B)
{
    return (A.x == B.x);
}
bool orizontal(POINT A,POINT B){
    return (fabs(A.y-B.y)<eps);
}
bool same_point(POINT A, POINT B)
{
    return fabs(A.x-B.x)<eps && fabs(A.y-B.y)<eps;
}
double panta(POINT A, POINT B)
{
    if(vertical(A,B))
        return INF;
    return (1.0*B.y-A.y)/(B.x-A.x);
}
vector<double> v;
vector<POINT> k;
int main()
{
     freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);
    int x , y;
    int n;
    scanf("%d",&n);
    for(int i = 1 ; i <= n ; ++i)
        {
            scanf("%d%d",&x,&y);
            POINT temp;
            temp.x = x;
            temp.y = y;
            k.push_back(temp);
        }
    for(int i = 0 ; i < k.size()-1 ; ++i)
        for(int j = i + 1 ; j < k.size() ; ++j)
            v.push_back(panta(k[i],k[j]));
    sort(v.begin(),v.end());
    int sum = 0;
    int ct = 0;
    ct = 1;
    for(int i = 1 ; i < v.size() ; i++)
    {
        if(v[i] == v[i-1])
            {
            ct++;
            }
        else{
        sum += (ct * (ct-1))/2;
        ct = 1;
        }
    }
    printf("%d",sum);
    return 0;
}