Cod sursa(job #1425146)

Utilizator czlateaZlatea Cezar czlatea Data 26 aprilie 2015 21:06:25
Problema Trapez Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const double INF=1.e+9;
const double eps=1.e-14;
struct PUNCT
{
    int x,y;
}v[1005];
double q[500000];
bool vert(PUNCT a,PUNCT b)
{
    return fabs(a.x-b.x)<eps;
}
void panta(PUNCT a,PUNCT b,int poz)
{
    if(vert(a,b))
    q[poz]=90;
    else
    q[poz]=(b.y-a.y)/(b.x-a.x);
}
int main()
{
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);
    int n,a,b,i;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d%d",&a,&b);
        v[i].x=a;
        v[i].y=b;
    }
    int j,poz=1;
    for(i=1;i<=n;i++)
        for(j=i+1;j<=n;j++)
    {
        panta(v[i],v[j],poz);
        poz++;
    }
    int nr=0;
    sort(q+1,q+poz);
    for(i=1;i<poz;i++)
    {
        if(q[i]==q[i+1])
        nr++;
        if(q[i-1]==q[i+2])
            nr--;
    }
        printf("%d",nr);

    return 0;
}