Pagini recente » Cod sursa (job #1265212) | Cod sursa (job #2864652) | Cod sursa (job #2969952) | Cod sursa (job #2731777) | Cod sursa (job #2734937)
#include <iostream>
#include <fstream>
#include <map>
using namespace std;
ifstream f ("trapez.in");
ofstream g ("trapez.out");
map<pair<int,int>,int>Map;
int n,rasp;
pair<int,int> puncte[1001];
int _gcd(int a,int b)
{
int r;
while(b)
{
r = a % b;
a = b;
b = r;
}
return a;
}
int main()
{
f >> n;
for(int i = 1; i<=n; i++)
{
f >> puncte[i].first>> puncte[i].second;
}
for(int i = 1; i<=n; i++)
{
for(int j = i+1; j<=n; j++)
{
int numarator = puncte[j].second - puncte[i].second;
int numitor = puncte[j].first - puncte[i].first;
int gcd = _gcd(numarator,numitor);
Map[ {numarator/gcd,numitor/gcd}]++;
}
}
for(auto x : Map)
{
rasp+=((x.second * (x.second-1))/2);
}
g << rasp;
}