Pagini recente » Cod sursa (job #2842880) | Cod sursa (job #1263969) | Cod sursa (job #2535844) | Rating Spaghetti Monster (spaghettimonster) | Cod sursa (job #2458183)
#include <fstream>
#include <cmath>
#include <algorithm>
#define EPS 0.000000001
#define NMAX 1005
#define LIM 2000000005
using namespace std;
ifstream fin("trapez.in");
ofstream fout("trapez.out");
struct punct
{
int x, y;
} v[NMAX];
double unghi[NMAX * NMAX];
int main()
{
int n;
fin >> n;
for(int i = 1; i <= n; ++i)
fin >> v[i].x >> v[i].y;
int cnt = 0;
for(int i = 1; i <= n; ++i)
for(int j = i + 1; j <= n; ++j){
if(v[i].x == v[j].x)
unghi[++cnt] = -LIM;
else
{
unghi[++cnt] = (abs(v[i].y - v[j].y) / (double)abs(v[i].x - v[j].x));
punct a = v[i];
punct b = v[j];
if(a.y < b.y)
swap(a, b);
if(a.x < b.x && a.y != b.y)
unghi[cnt] += LIM;
}
}
sort(unghi + 1, unghi + cnt + 1);
int lg = 1, rez = 0;
for(int i = 2; i <= cnt; ++i){
if(unghi[i] - unghi[i - 1] < EPS)
++lg;
else {
rez += (lg - 1) * lg / 2;
lg = 1;
}
}
rez += (lg - 1) * lg / 2;
fout << rez << '\n';
return 0;
}