Pagini recente » Cod sursa (job #2194658) | Cod sursa (job #601423) | Cod sursa (job #466167) | Cod sursa (job #1192381) | Cod sursa (job #1019187)
#include <fstream>
#include <vector>
#include <unordered_map>
using namespace std;
ifstream cin ("trapez.in");
ofstream cout("trapez.out");
struct Point
{
int x, y;
};
double slope (int x1, int y1, int x2, int y2)
{
return (double)(x2 - x1) / (double) (y2 - y1);
}
int main()
{
int n; cin >> n;
vector<Point> nr;
unordered_map<double, int> myHash;
for (int i = 0; i < n; ++i)
{
int x, y;
cin >> x >> y;
Point p; p.x = x; p.y = y;
nr.push_back(p);
}
for (vector<Point>::iterator i = nr.begin(); i != nr.end(); ++i)
for (vector<Point>::iterator j = i + 1; j != nr.end(); ++j)
myHash[slope( (*i).x, (*i).y, (*j).x, (*j).y )]++;
int sum = 0;
for (unordered_map<double, int>::iterator i = myHash.begin(); i != myHash.end(); ++i)
{
int slopeCnt = (*i).second;
sum += slopeCnt * (slopeCnt - 1) / 2;
}
cout << sum << "\n";
cin .close();
cout.close();
return 0;
}