Cod sursa(job #578674)

Utilizator eukristianCristian L. eukristian Data 11 aprilie 2011 14:51:58
Problema Medie Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define _fin  "medie.in"
#define _fout "medie.out"

# define MaxN 9002
# define MaxX 7002


int  a[MaxN], rep[MaxX], n;
long sol;


void readf()
{
	int i;
	FILE *fin = fopen(_fin, "r");

	for(fscanf(fin, "%d", &n), i=1; i<=n; i++)
		fscanf(fin, "%d", a+i);

	fclose(fin);
}

void writef()
{
	FILE *fout = fopen(_fout, "w");
	fprintf(fout, "%ld\n", sol), fclose(fout);
}

long  v[MaxX];
//int rep[MaxX];
/*
   v[i] = numarul de perechi din sir care au media aritmetica i
*/

void solve()
{
	int i, j, p, step, vs, c, aux;


# define div2(x) ( ! ((x) & 1) )

	for(i=1; i<n; i++)
	{
		++rep[ a[i] ];

		for(j=i+1; j<=n; j++)
			if ( div2( aux=a[i]+a[j] ) )
				++v[aux>>1];
	}

	++rep[a[n]];

	for(i=1; i<=n; i++)
		if ( v[ a[i] ] )
			sol += long( v[ a[i] ] - rep[ a[i] ] + 1 );
}

int main()
{
	readf();
	solve();
	writef();

	return 0;
}