Cod sursa(job #1981384)

Utilizator rebecca0312Andrei Rebecca rebecca0312 Data 15 mai 2017 15:57:07
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.98 kb
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const double eps=1.e-14;
const double INF=2000000005;
struct POINT{
    double x,y;
}z;
vector <POINT> v;
vector <double> pant;
double panta(POINT A, POINT B){
    if(fabs(A.x-B.x)<eps)
        return INF;
    return (1.0*B.y-A.y)/(B.x-A.x);
}
int main(){
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);
    int n;
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        scanf("%lf%lf", &z.x, &z.y);
        v.push_back(z);
    }
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
            pant.push_back(panta(v[i], v[j]));
    sort(pant.begin(), pant.end());
    long long sol=0;
    for(int i=0;i<(int)pant.size();i++){
        int ind=i,nr=0;
        while(i<(int)pant.size() && fabs(pant[i]-pant[ind])<eps){
            i++;
            nr++;
        }
        i--;
        sol+=1LL*nr*(nr-1)/2;
    }
    printf("%lld", sol);
    return 0;
}