Pagini recente » Cod sursa (job #101048) | Cod sursa (job #2049307) | Cod sursa (job #2553431) | Cod sursa (job #1308258) | Cod sursa (job #1993603)
#include <fstream>
#include <algorithm>
#define MAX 1002
#define inf 0x3f3f3f3f
using namespace std;
ifstream fin("trapez.in");
ofstream fout("trapez.out");
struct{
int x,y;
}P[MAX];
int n,cnt=-1;
double segmente[MAX*MAX];
long long rez;
int main()
{
fin >> n;
for (int i=0;i<n;i++)
fin >> P[i].x >> P[i].y;
for (int i=0;i<n-1;i++)
for (int j=i+1;j<n;j++)
{
double aux;
double a=P[j].x-P[i].x;
double b=P[j].y-P[i].y;
if (a)
aux=b/a;
else if (b>0)aux=inf;
else aux=-inf;
segmente[++cnt]=aux;
}
sort (segmente,segmente+cnt+1);
segmente[++cnt]=inf;
int nr=1;
for (int i=1;i<cnt;i++)
if (segmente[i]==segmente[i-1])
nr++;
else
{
rez+=nr*(nr-1)/2;
nr=1;
}
fout << rez;
return 0;
}