Pagini recente » Cod sursa (job #1741349) | Cod sursa (job #1267825) | Cod sursa (job #1267760) | Cod sursa (job #2859202) | Cod sursa (job #2221301)
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cmath>
using namespace std;
const double INF=1e9;
const double eps=1e-9;
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){
if(ans==*it)
++k;
else{
total+=(k*(k-1)/2);
k=1;
ans=*it;
}
}
total+=(k*(k-1)/2);
printf("%ld",total);
return 0;
}