Cod sursa(job #1729126)

Utilizator cristina_borzaCristina Borza cristina_borza Data 14 iulie 2016 12:02:51
Problema Medie Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <fstream>
#include <cstdio>

#define NMAX 9005
#define DIM 7005

using namespace std;

int c[DIM] , v[NMAX];
int n , sol;

template <class T>

void read(T &x) {
    char ch;
    x = 0;

    while (!isdigit(ch = getchar())) {

    }

    do {
        x = x * 10 + ch - '0';
    }while (isdigit(ch = getchar()));
}

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

    read(n);
    for (int i = 1; i <= n; ++i) {
        read(v[i]);
        ++c[v[i]];
    }

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j < i; ++j) {
            int aux = v[i] + v[j];
            if (aux % 2 == 0) {
                aux /= 2;

                sol += c[aux];
                if (v[i] == aux) {
                    --sol;
                }

                if (v[j] == aux) {
                    --sol;
                }
            }
        }
    }

    printf("%d" , sol);
    return 0;
}