Cod sursa(job #183839)

Utilizator Mishu91Andrei Misarca Mishu91 Data 22 aprilie 2008 17:34:13
Problema Medie Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <cstdio>
#include <string>
#define Nmax 9001
#define Xmax 7001

int V[Nmax], N;

void citire()
{
    scanf("%d",&N);
    for(int i=0; i<N; i++)
        scanf("%d",V+i);
}

void solve()
{
    long nr = 0,w[Xmax];
    memset(w,0,sizeof w);
    int m;

    for(int i=0; i<N; i++)
        w[V[i]]++;
    for(int i=0; i<N-1; i++)
        for(int j=i+1; j<N; j++)
            if(!((V[i] + V[j]) & 1 ) && w[m = (V[i] + V[j]) >> 1])
                nr += (V[i] == V[j])? w[m] - 2 : w[m];
    printf("%ld\n",nr);
}

int main()
{
    freopen("medie.in","r",stdin);
    freopen("medie.out","w",stdout);
    citire();
    solve();
}