Pagini recente » Cod sursa (job #1815227) | Cod sursa (job #2107472) | Cod sursa (job #1964910) | Cod sursa (job #2394335) | Cod sursa (job #2221308)
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cmath>
using namespace std;
const double INF=1e9;
const double eps=1.e-14;
class Point{
private:
short x,y;
public:
Point(){
x=0; y=0;
}
Point(short a, short b){
x=a; y=b;
}
void set(short a, short b){
x=a; y=b;
}
friend bool operator < (const Point &other1, const Point &other2){
if(other1.x<other1.y)
return true;
if(other1.x==other1.y)
return other1.y < other1.x;
return false;
}
bool operator == (const Point &other){
return (x==other.x) && (y==other.y);
}
double panta(const Point &other){
if(fabs(x-other.x)<eps)
return INF;
return 1.0*(y-other.y)/(x-other.x);
}
};
long total=0;
short n;
short x,y;
double ans;
vector <Point> v;
vector <double> f;
int main()
{
long i,j;
vector <double>::iterator it;
Point neww;
freopen("trapez.in","r",stdin);
freopen("trapez.out","w",stdout);
scanf("%hd",&n);
for(i=1; i<=n; ++i){
scanf("%hd %hd",&x,&y);
neww.set(x,y);
v.push_back(neww);
}
for(i=0; i<n; ++i)
for(j=i+1; j<n; ++j){
ans=v[i].panta(v[j]);
f.push_back(ans);
}
sort(f.begin(),f.end());
ans=f[0];
long k=1;
for(it=f.begin()+1; it!= f.end(); ++it){
//printf("%f\n",(*it));
if(fabs(ans-*it)<eps)
++k;
else{
total+=(k*(k-1))/2;
k=1;
ans=*it;
}
}
total+=(k*(k-1))/2;
printf("%ld",total);
return 0;
}