Cod sursa(job #1993052)

Utilizator Dobricean_IoanDobricean Ionut Dobricean_Ioan Data 22 iunie 2017 11:29:41
Problema Trapez Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
ifstream fin ("trapez.in");
ofstream fout ("trapez.out");
int sol;
#define eps 0.0001

struct punct{
int x,y;
};

struct segm{
punct a,b;
bool operator < (const segm& S) const
    {
        return (b.y - a.y) * (S.b.x - S.a.x)
              - (S.b.x - a.x)* (S.b.y - S.a.y)< 0;
    }
};
segm S [10000001];
punct p [1001];


int main() {
	 int i,j,nrseg=0,n,cnt=1;
	fin >> n;
	for(i = 0; i < n; i ++ )
		fin >> p[i].x >> p[i].y;
	//Construiesc Segmente
	for( i = 0; i < n;  i ++ )
		for( j= i + 1; j < n; j ++) {
			S [ nrseg ].a.x = p [i].x;
			S [ nrseg ].a.y = p [i].y;
			S [ nrseg ].b.x = p [j].x;
			S [ nrseg++ ].b.y = p [j].y;
			}

sort(S,S+nrseg);

for( i = 1; i < nrseg; i ++)
	if(fabs( (S[i-1].b.y-S[i-1].a.y) * (S[i].b.x-S[i].a.x) - (S[i-1].b.x-S[i-1].a.x) * (S[i].b.y-S[i].a.y) ) < eps)
			cnt++;
		else {
					sol+=cnt*(cnt-1)/2;
		cnt=1;
		}
		fout << sol;
	
}