Pagini recente » Cod sursa (job #851428) | Cod sursa (job #1954135) | Cod sursa (job #654524) | Cod sursa (job #613637) | Cod sursa (job #1993064)
#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;
double tan;
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];
bool Vertical(punct A, punct B)
{
return fabs(A.x - B.x) < eps;
}
double Panta(punct A, punct B)
{ if(Vertical (A,B))
return -1;
return (double)(B.y - A.y) / (B.x - A.x);
}
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;
S [nrseg++].tan=Panta(p[i],p[j]);
}
sort(S,S+nrseg);
for( i = 1; i < nrseg; i ++)
if(fabs (S [i].tan-S [i-1].tan)<eps)
cnt++;
else {
sol+=cnt*(cnt-1)/2;
cnt=1;
}
fout << sol;
}