Pagini recente » Cod sursa (job #1038593) | Cod sursa (job #450461) | Cod sursa (job #334715) | Cod sursa (job #2845009) | Cod sursa (job #2703229)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin ("trapez.in");
ofstream fout ("trapez.out");
struct coordonate{
int x, y;
};
coordonate v[1001], p[499501];
int comparare1(coordonate a, coordonate b){
return (a.y < b.y) || ( (a.y == b.y) && (a.x <= b.x) );
}
int comparare2(coordonate a, coordonate b){
//vreau ca tg a <= tg b
// a.y / a.x <= b.y / b.x
// a.y * b.x <= b.y * a.x
return (a.y * b.x <= b.y * a.x);
}
int main()
{
int n, k=0, l=1, nrsol=0;
fin>>n;
for(int i=1; i<=n; i++){
fin>>v[i].x>>v[i].y;
}
sort(v+1, v+n+1, comparare1);
for(int i=1; i<=n; i++){
for(int j=i + 1; j<=n; j++){
k++;
p[k].x = v[j].x - v[i].x;
p[k].y = v[j].y - v[i].y;
}
}
sort(p+1, p+k+1, comparare2);
//vad cate am consecutive la fel
l=1;
for(int i=2; i<=k; i++){
//p[i-1].x / p[i-1].y == p[i].x / p[i].y;
//p[i-1].x * p[i].y = p[i].x * p[i-1].y
if(1LL * p[i].x * p[i - 1].y == 1LL * p[i - 1].x * p[i].y){
l++;
}
else{
nrsol += l * (l - 1) / 2;
l=1;
}
}
nrsol += l * (l - 1) / 2;
fout<<nrsol;
}