Cod sursa(job #2073748)

Utilizator Data 23 noiembrie 2017 17:28:57 Trapez 100 cpp done Arhiva de probleme 1.22 kb
``````#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const double eps=1.e-14;
const double INF=2.e9;
struct POINT
{
double x,y;
};
bool vertical(POINT p1,POINT p2)
{
return fabs(p1.x-p2.x)<eps;
}
double panta(POINT p1,POINT p2)
{
if(vertical(p1,p2))
return INF;
return (p2.y-p1.y)/(p2.x-p1.x);
}
POINT points[1005];
double ang[500005];
int main()
{
freopen("trapez.in","r",stdin);
freopen("trapez.out","w",stdout);
int n,i,x,y,j,nr,flag,l;
long long rez;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d%d",&x,&y);
points[i].x=x;
points[i].y=y;
}
nr=0;
for(i=1;i<=n;i++)
for(j=i+1;j<=n;j++)
ang[++nr]=panta(points[i],points[j]);
sort(ang+1,ang+nr+1);
rez=0;
flag=0;
l=0;
for(i=nr;ang[i]==INF;--i)
nr--;
for(i=1;i<=nr;i++)
{
if(fabs(ang[i]-ang[i-1])<eps && flag==0){
flag=1;
l=0;
}
if(fabs(ang[i]-ang[i-1])<eps && flag==1)
l++;
if(fabs(ang[i]-ang[i-1])>eps && flag==1)
{
rez=rez+l*(l+1)/2;
flag=0;
}
}
printf("%d",rez);
return 0;
}
``````