Pagini recente » Cod sursa (job #1289174) | Cod sursa (job #2415848) | Cod sursa (job #2607656) | Cod sursa (job #2087572) | Cod sursa (job #1295065)
#include <cstdio>
#include <algorithm>
using namespace std;
const int NMAX = 1010;
int N, X[NMAX], Y[NMAX], Ans, K;
struct Slope
{
int DX, DY;
}S[NMAX * NMAX];
struct Comp
{
bool operator() (const Slope &A, const Slope &B) const
{
return 1LL * A.DY * B.DX < 1LL * A.DX * B.DY;
}
};
int main()
{
freopen("trapez.in", "r", stdin);
freopen("trapez.out", "w", stdout);
scanf("%i", &N);
for(int i = 1; i <= N; ++ i)
scanf("%i %i", &X[i], &Y[i]);
for(int i = 1; i <= N; ++ i)
for(int j = i + 1; j <= N; ++ j)
S[++ K].DX = X[j] - X[i], S[K].DY = Y[j] - Y[i];
sort(S + 1, S + K + 1, Comp());
S[0].DX = S[1].DX - 1;
S[0].DY = S[1].DY;
int CntEqual = 0;
for(int i = 1; i <= K; ++ i)
if(1LL * S[i - 1].DY * S[i].DX == 1LL * S[i - 1].DX * S[i].DY)
CntEqual ++;
else
{
Ans += (CntEqual * (CntEqual - 1)) / 2;
CntEqual = 1;
}
Ans += (CntEqual * (CntEqual - 1)) / 2;
printf("%i\n", Ans);
}