Pagini recente » Cod sursa (job #332028) | Cod sursa (job #1289956) | Cod sursa (job #2983201) | Cod sursa (job #847481) | Cod sursa (job #1081225)
//
// main.cpp
// trapez
//
// Created by Alexandru Bâgu on 1/13/14.
// Copyright (c) 2014 Alexandru Bâgu. All rights reserved.
//
#include <stdio.h>
#include <algorithm>
#include <memory.h>
using namespace std;
typedef struct {
int x, y;
} coord;
double slope(coord a, coord b)
{
return (double)(b.y - a.y) / (double)(b.x - a.x);
}
int main(int argc, const char * argv[])
{
freopen("trapez.in", "r", stdin);
freopen("trapez.out", "w", stdout);
int n;
scanf("%d", &n);
coord* C = new coord[n];
int i, j, tx = 0, q;
for(i = 0; i < n; i++)
scanf("%d %d", &C[i].x, &C[i].y);
double* L = new double[n * n];
for(i = 0; i < n - 1; i++)
for(j = i + 1; j < n; j++)
L[tx++] = slope(C[i], C[j]);
sort(L, L + tx);
int tr = 0;
i = 0;
while (i < tx)
{
j = i;
while(j < tx && L[i] == L[j]) j++;
q = j - i - 1;
tr += q + (q -1) / 2;
i = j;
}
printf("%d", tr);
return 0;
}