Pagini recente » Cod sursa (job #2453624) | Cod sursa (job #801760) | Cod sursa (job #903868) | Cod sursa (job #2038530) | Cod sursa (job #982698)
Cod sursa(job #982698)
#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 GetTrapeze()
{
sort(pante.begin(),pante.end());
Segmente=1;
for(int i=1;i<(int)pante.size();i++)
if(fabs(pante[i]-pante[i-1])<eps)Segmente++;
else
{
Trapeze+=(Segmente*(Segmente-1)/2);
Segmente=1;
}
g<<Trapeze<<'\n';
}
int main()
{
ReadInput();
FormeazaPantele();
GetTrapeze();
f.close();g.close();
return 0;
}