Pagini recente » Cod sursa (job #149656) | Cod sursa (job #2573057) | Cod sursa (job #1353951) | Cod sursa (job #429366) | Cod sursa (job #2748873)
#include <fstream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
const double eps = 1.0e-14;
const double INF = 1e9;
ifstream cin("trapez.in");
ofstream cout("trapez.out");
class POINT
{
private:
double x,y;
public:
//Constuctori
POINT()
{
x = y = 0;
}
POINT(double _x, double _y)
{
x = _x;
y = _y;
}
POINT(const POINT &other)
{
x = other.x;
y = other.y;
}
int getx()
{
return x;
}
int gety()
{
return y;
}
void setxy(double _x, double _y)
{
x = _x;
y = _y;
}
double dist(const POINT &other)
{
return sqrt((x-other.x)*(x-other.x)+(y-other.y)*(y-other.y));
}
POINT mijloc(const POINT &other)
{
POINT temp;
temp.x = (x+other.x)*0.5;
temp.y = (y+other.y)*0.5;
return temp;
}
double panta(const POINT &other)
{
if(fabs(x-other.x)<eps)
return INF;
return (y-other.y)/(x-other.x);
}
bool operator ==(const POINT &other)
{
return (fabs(x-other.x)<eps) && (fabs(y-other.y)<eps);
}
bool operator <(const POINT &other)
{
if(fabs(x-other.x)>eps)
return x<other.x;
return y<other.y;
}
};
int main()
{
int n,i,tx,ty,j,nr = 0,dr;
vector<POINT> vt;
vector<double> pante;
POINT temp;
cin >> n;
for(i=0;i<n;i++)
{
cin >> tx >> ty;
temp.setxy(tx,ty);
vt.push_back(temp);
}
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
{
pante.push_back(vt[i].pante(vt[j]));
}
sort(pante.begin(),pante.end());
dr=1;
for(i=1;i<pante.size();i++)
{
if(fabs(pante[i]-pante[i-1])<eps)
{
dr++;
}
else
{
if(dr>1)
nr=nr+(dr*(dr-1))/2;
dr=1;
}
}
cout<<nr;
return 0;
}