Pagini recente » Cod sursa (job #2309742) | Cod sursa (job #2953577) | Cod sursa (job #1105805) | Cod sursa (job #1826351) | Cod sursa (job #982700)
Cod sursa(job #982700)
#include <fstream>
#include <algorithm>
#include <math.h>
#include <vector>
#define Nmax 1099
#define x first
#define y second
#define Inf 2000000000
#define eps 0.00000000000001
using namespace std;
ifstream f("trapez.in");
ofstream g("trapez.out");
int n,Trapeze,Segmente;
pair<int,int> v[Nmax];
vector<long double> pante;
void ReadInput()
{
f>>n;
for(int i=1;i<=n;i++)f>>v[i].x>>v[i].y;
}
long double GetPanta(pair<int,int> a, pair<int,int> b)
{
if(a.x==b.x) return Inf;
return (long double)(b.y-a.y)/(long double)(b.x-a.x);
}
void FormeazaPantele()
{
for(int i=1;i<=n-1;i++)
for(int j=i+1;j<=n;j++)
pante.push_back(GetPanta(v[i],v[j]));
}
void NumaraTrapeze()
{
sort(pante.begin(),pante.end());
//numat segmente sunt pararelele dupa o directie
Segmente=1;
for(int i=1;i<(int)pante.size();i++)
if(pante[i]-pante[i-1]<eps)Segmente++;
else
{
//pot sa fac un trapez alegand in toate modurile posibile 2 segmente
Trapeze+=(Segmente*(Segmente-1)/2);
Segmente=1;
}
g<<Trapeze<<'\n';
}
int main()
{
ReadInput();
FormeazaPantele();
NumaraTrapeze();
f.close();g.close();
return 0;
}