Cod sursa(job #235392)

Utilizator DraStiKDragos Oprica DraStiK Data 23 decembrie 2008 18:19:01
Problema Numarare triunghiuri Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <stdio.h>
int a[805];
int n,nrt;
int maxim (int i,int j,int k)
{
    int c[4],x,y;
    c[1]=a[i];
    c[2]=a[j];
    c[3]=a[k];
    for (x=1; x<4; ++x)
        for (y=x+1; y<=4; ++y)
            if (c[x]<c[y])
            {
                c[x]^=c[y];
                c[y]^=c[x];
                c[x]^=c[y];                                
            }
    if (c[1]<=c[2]+c[3])
        return 1;
    else
        return 0;
}
int main ()
{
    freopen ("nrtri.in","r",stdin);
    freopen ("nrtri.out","w",stdout);
    int i,j,k,max1,max2,max3;
    scanf ("%d",&n);
    for (i=1; i<=n; ++i)
        scanf ("%d",&a[i]);
    for (i=1; i<=n-2; ++i)
        for (j=i+1; j<=n-1; ++j)
            for (k=j+1; k<=n; ++k)
                if (maxim (i,j,k))
                    ++nrt;
    printf ("%d",nrt);
    return 0;
}