Pagini recente » Cod sursa (job #3003875) | Cod sursa (job #367167) | Cod sursa (job #873577) | Cod sursa (job #142240) | Cod sursa (job #2455722)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long lint;
int gcd(int a, int b)
{
if(b == 0){
return a;
}
return gcd(b, a%b);
}
struct boi{
int a, b;
void yeet()
{
cout << a << " " << b << "\n";
}
void susta()
{
int x = gcd(a, b);
a /= x; b /= x;
}
void susta_reloaded()
{
if((a <= 0 && b <= 0) || (a <= 0 && b >= 0)){
a = -a; b = -b;
}
}
};
bool operator<(const boi & lhs, const boi & rhs)
{
return lhs.a < rhs.a || (lhs.a == rhs.a && lhs.b < rhs.b);
}
bool operator==(const boi & lhs, const boi & rhs)
{
return lhs.a == rhs.a && lhs.b == rhs.b;
}
int trap(int a)
{
return a*(a-1)/2;
}
ifstream fin("trapez.in");
ofstream fout("trapez.out");
vector<boi> points;
vector<boi> parale;
int main()
{
int n;
fin >> n;
for(int i = 0; i < n; i++){
int a, b;
fin >> a >> b;
points.push_back({a, b});
}
for(int i = 0; i < n; i++){
boi p1 = points[i];
for(int j = i+1; j < n; j++){
boi p2 = points[j];
boi ln = {p1.a - p2.a, p1.b - p2.b};
ln.susta();
ln.susta_reloaded();
parale.push_back(ln);
}
}
sort(parale.begin(), parale.end());
lint sol = 0;
boi ex = parale.front();
int st = 0;
for(auto ln : parale){
if(ln == ex){
st++;
}else{
sol += trap(st);
ex = ln;
st = 1;
}
}
sol += trap(st);
fout << sol;
return 0;
}