Pagini recente » Cod sursa (job #934286) | Cod sursa (job #518406) | Cod sursa (job #2190237) | Cod sursa (job #2207349) | Cod sursa (job #2608536)
#include <fstream>
#include <utility>
#include <unordered_map>
#include <map>
using namespace std;
typedef long long LL;
int GCD(LL a, LL b)
{
while (b != 0)
{
int r = a % b;
a = b;
b = r;
}
return a;
}
int main()
{
int n;
ifstream fin("trapez.in");
fin >> n;
pair<LL, LL>* coords = new pair<LL, LL>[n];
for (int i = 0; i < n; i++)
{
pair<LL, LL> crt;
fin >> crt.first >> crt.second;
coords[i] = crt;
}
fin.close();
map<pair<LL, LL>, LL> vectors;
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
LL dx = coords[i].first - coords[j].first;
LL dy = coords[i].second - coords[j].second;
LL l = GCD(abs(dx), abs(dy));
dx /= l;
dy /= l;
if (dx == 0)
{
if (dy < 0)
dy = -dy;
}
else
if (dx < 0)
{
dx = -dx;
dy = -dy;
}
pair<LL, LL> vec = make_pair(dx, dy);
if (vectors.find(vec) == vectors.end())
vectors[vec] = 0;
vectors[vec]++;
}
}
delete[] coords;
coords = NULL;
LL result = 0;
for (auto cnt : vectors)
result += cnt.second * (cnt.second - 1) / 2;
ofstream fout("trapez.out");
fout << result;
fout.close();
return 0;
}