Pagini recente » Cod sursa (job #309015) | Cod sursa (job #2312379) | Cod sursa (job #760598) | Cod sursa (job #2221404) | Cod sursa (job #828511)
Cod sursa(job #828511)
#include <algorithm>
#include <iostream>
using namespace std;
#include <stdio.h>
#include <math.h>
struct punct
{
public:
long x,y;
};
int main()
{
FILE *in=fopen("trapez.in","r"),*out=fopen("trapez.out","w");
int N;
fscanf(in,"%d",&N);
punct t[N];
float st[N*(N-1)/2+2];
for(int i=0;i<N;i++)
{
fscanf(in,"%ld",&t[i].x);
fscanf(in,"%ld",&t[i].y);
}
long k=0;
for(int i=0;i<N-1;i++) //1
for(int j=i+1;j<N;j++) //2
{
if(t[i].y>t[j].y && t[i].x!=t[j].x)
st[k++]=(float)((float)(t[i].y-t[j].y)/(float)(t[i].x-t[j].x));
else
if(t[i].x!=t[j].x)
st[k++]=(float)((float)(t[j].y-t[i].y)/(float)(t[j].x-t[i].x));
if(t[i].x==t[j].x)st[k++]=-99999.98;
}
sort(st,st+k+1);
long R=0;
int e,j;
for(int i=0;i<k-1;i++)
{
e=1;
for( j=i,e=1;st[j]==st[j+1];j++)
e++;
R+= e*(e-1)/2;
i+=e-1;
}
fprintf(out,"%ld",R);
}