Cod sursa(job #183819)

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

int V[Nmax], w[Xmax],N;

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

void solve()
{
    int nr = 0;

    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++)
        {
            int m = (V[i] + V[j]) >> 1;
            if(((V[i] + V[j]) & 1 )== 0 && w[m])
                nr += (V[i] == V[j])? w[m] - 2 : w[m];
        }
    printf("%d\n",nr);
}

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