Pagini recente » Cod sursa (job #1942117) | Cod sursa (job #1276324) | Cod sursa (job #369552) | Cod sursa (job #1818937) | Cod sursa (job #2479278)
//
// main.cpp
// Trapez
//
// Created by Darius Buhai on 23/10/2019.
// Copyright © 2019 Darius Buhai. All rights reserved.
//
#include <iostream>
#include <fstream>
#include <vector>
#define INF 9999999
using namespace std;
ifstream fin("trapez.in");
ofstream fout("trapez.out");
struct point{
int x, y;
};
struct slopes{
float m;
int count, nt;
};
float calculate_slope(point a, point b){
if(a.x==b.x) return INF;
return ((float)(a.y-b.y))/((float)(a.x-b.x));
}
int main() {
int n;
float m;
point c;
vector<point> a;
vector<slopes> s;
fin>>n;
for(int i=0;i<n;i++){
fin>>c.x>>c.y;
if(i>0)
for(auto ai : a){
bool found = false;
m = calculate_slope(ai, c);
for(int j=0;j<s.size();j++)
if(s[j].m==m){
s[j].nt+=s[j].count;
s[j].count++;
found = true;
}
if(!found) s.push_back({m, 1, 0});
}
a.push_back(c);
}
int rez = 0;
for(auto si : s)
if(si.count>1)
rez+=si.nt;
fout<<rez;
return 0;
}