Pagini recente » Cod sursa (job #1638103) | Cod sursa (job #2556234) | Cod sursa (job #2673342) | Cod sursa (job #2219003) | Cod sursa (job #2067737)
#include<bits/stdc++.h>
#include<iostream>
#include<fstream>
using namespace std;
ifstream in("trapez.in");
ofstream out("trapez.out");
const double INF = 2000000001;
const int N_MAX = 1000;
int n;
double calcSlope(pair<int, int> point1, pair<int, int> point2){
double vertical_distance = point2.second - point1.second;
double horizontal_distance = point2.first - point1.first;
if(horizontal_distance == 0) /// Don't divide by 0!
{
if(vertical_distance < 0)
return -INF;
else
return INF;
}
/// Return the tangent of the two points
return vertical_distance / horizontal_distance;
}
int main()
{
unordered_map<double, int> slopeCount;
pair<int, int> point[N_MAX];
in>>n;
for(int i=0; i<n; ++i)
in>>point[i].first>>point[i].second;
for(int i=0; i<n; ++i)
for(int j=i+1; j<n; ++j)
{
double crtSlope = calcSlope(point[i], point[j]);
++slopeCount[crtSlope];
}
long long answer = 0;
for(unordered_map<double, int>::iterator it = slopeCount.begin(); it != slopeCount.end(); ++it)
{
///cout<<it->first<<" "<<it->second<<"\n";
answer += (long long)(it->second) * (it->second-1) / 2;
}
out<<answer;
return 0;
}