Pagini recente » Cod sursa (job #371065) | Cod sursa (job #2267999) | Cod sursa (job #453251) | the_wild_west | Cod sursa (job #2220657)
#include <fstream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
ifstream fin("trapez.in");
ofstream fout("trapez.out");
vector <double> v;
const double eps=1.e-14;
const double INF=1.e9;
class POINT
{
private:
double x,y;
public:
POINT()
{
x=y=0;
}
POINT(double _x, double _y)
{
x=_x;
y=_y;
}
POINT(const POINT &other)
{
x=other.x;
y=other.y;
}
void set(double _x, double _y)
{
x=_x;
y=_y;
}
double getx()
{
return x;
}
double gety()
{
return y;
}
double dist(const POINT &other)
{
return sqrt((x-other.x)*(x-other.x)+(y-other.y)*(y-other.y));
}
friend double dist(const POINT &p1, const POINT &p2)
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.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;
else
return (y-other.y)/(x-other.x);
}
};
POINT a[1005];
int main()
{
int i,n,j,k,z=1,cont=0,st,dr;double p,r;bool ok=1;
POINT temp;
fin>>n;
for(i=1;i<=n;i++)
{
fin>>j>>k;
temp.set(j,k);
a[i]=temp;
}
v.push_back(INF);
for(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
p=a[i].panta(a[j]);
v.push_back(p);
}
}
sort(v.begin(),v.end());
z=v.size()-1;
for(i=0;i<z-1;i++)
{
p=v[i];ok=1;k=1;
for(j=i+1;j<z && ok==1;j++)
{
r=v[j];
if(fabs(p-r)>eps)
ok=0;
else
k++;
}
i=j-1;
cont=cont+(k-1)*k/2;
}
fout<<cont;
return 0;
}