Pagini recente » Cod sursa (job #2860852) | Cod sursa (job #1115041) | Cod sursa (job #2460818) | Cod sursa (job #295428) | Cod sursa (job #3154659)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("trapez.in");
ofstream fout("trapez.out");
bool compare(pair<int, int> a, pair<int, int> b){
if (a.second == b.second)
return a.first < b.first;
return a.second < b.second;
}
int euclid(int a, int b){
if (b == 0)
return a;
int rezultat = euclid(b, a % b);
return rezultat;
}
pair<int, int> panta(pair<int, int> a, pair<int, int> b){
pair<int, int> fractie;
fractie.first = b.second - a.second;
fractie.second = b.first - a.first;
int cmmdc = euclid(fractie.first, fractie.second);
fractie.first /= cmmdc;
fractie.second /= cmmdc;
return fractie;
};
int main(){
pair<int, int> dr[1001];
pair<int, int> pante[1000001];
int drepte, contor_pante = 0;
fin >> drepte;
for (int i = 1; i <= drepte; i++) {
fin >> dr[i].first >> dr[i].second;
}
for (int i = 1; i < drepte; i++){
for (int j = i + 1; j <= drepte; j++){
contor_pante++;
pante[contor_pante] = panta(dr[i], dr[j]);
}
}
sort(pante+1, pante+1+contor_pante, compare);
int answer = 0;
int contor_pante_egale_consecutive = 0;
for (int i = 1; i <= contor_pante; i++){
if (pante[i - 1].first == pante[i].first && pante[i-1].second == pante[i].second)
contor_pante_egale_consecutive++;
else {
answer += ((contor_pante_egale_consecutive - 1) * contor_pante_egale_consecutive) / 2;
contor_pante_egale_consecutive = 1;
}
}
answer += ((contor_pante_egale_consecutive - 1) * contor_pante_egale_consecutive) / 2;
fout << answer;
return 0;
}