Pagini recente » Cod sursa (job #2085416) | Cod sursa (job #726804) | Cod sursa (job #941152) | Cod sursa (job #874319) | Cod sursa (job #2551369)
#include <bits/stdc++.h>
using namespace std;
ifstream f("trapez.in");
ofstream g("trapez.out");
const int NMAX = 1005;
const int inf = 1e9;
const double ihopeno = 0.00000000000000001;
vector < double > slope;
pair < int, int > v[NMAX];
int n,ans;
double ecu(const pair < int, int > &Y, const pair < int, int > &X){
if(X.first == Y.first)
return inf;
return (double(X.second - Y.second) / double(X.first - Y.first));
}
double MODULUSBABANUS(double x){
return max(x, -x);
}
bool equality(double &X, double &Y){
return (MODULUSBABANUS(X - Y) < ihopeno);
}
int main(){
int i,j;
double x;
f >> n;
for(i = 1 ; i <= n ; i++){
f >> v[i].first >> v[i].second;
for(j = i - 1 ; j >= 1 ; j--){
x = ecu(v[i], v[j]);
slope.push_back(x);
}
}
sort(slope.begin(), slope.end());
int leng = 0;
for(i = 1 ; i < slope.size() ; i++){
if(equality(slope[i], slope[i - 1]))
leng++;
else{
ans += leng * (leng - 1) / 2;
leng = 1;
}
}
ans += leng * (leng - 1) / 2;
g << ans;
return 0;
}