Pagini recente » Cod sursa (job #1089372) | Cod sursa (job #304435) | Cod sursa (job #931451) | Cod sursa (job #2634045) | Cod sursa (job #1981427)
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
const double eps = 1.e-14;
const double inf = 2.e9;
struct POINT{
double x;
double y;
};
double panta(POINT A, POINT B){
if(fabs(A.x - B.x)<eps)return inf;
return((B.y - A.y)/(B.x-A.x));
}
int main()
{
ifstream in("trapez.in");
ofstream out("trapez.out");
int n;
in >> n;
vector<POINT> v;
vector<double>pv;
for(int i = 1; i <= n; i++){
POINT p;
in >> p.x >> p.y;
v.push_back(p);
}
for(int i = 1; i <= v.size(); i++){
for(int j = i; j <= v.size(); j++){
pv.push_back(panta(v[i],v[j]));
}
}
sort(pv.begin(), pv.end());
int trapeze = 0;
int nop = 0;
for(int i = 1; i < pv.size(); i++){
//cout << pv[i] << endl;
if(fabs(pv[i+1] - pv[i])<eps && pv[i]!=inf){
nop++;
}
else{
if(nop!=0)
trapeze = trapeze + nop*(nop+1)/2;
nop = 0;
}
}
out << trapeze;
return 0;
}