Cod sursa(job #911138)

Utilizator NicuCJNicu B. NicuCJ Data 11 martie 2013 12:54:21
Problema Medie Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <fstream>
#include <vector>
#define mh 631
using namespace std;
vector<short> hsh[mh];
void push_hash(int k, int s, int t)
{
	int mod=k%mh;
	hsh[mod].push_back(k);
}
int search_hash(int k, int s)
{
	int mod=k%mh, contor=0;
	int i;
	for(i=0; i<hsh[mod].size(); i++)
	{
		if(hsh[mod][i]==k)
		{
			contor++;
		}
	}
	return contor;
}
int sum, n, i, x[9001], j;
int main()
{
	ifstream f("medie.in");
	ofstream g("medie.out");
	f>>n;
	for(i=1; i<=n; i++)
	{
		f>>x[i];
	}
	for(i=1; i<=n; i++)
	{
		for(j=i+1; j<=n; j++)
		{
			if((x[i]+x[j])%2==0)
			{
				push_hash((x[i]+x[j])/2, i, j);
				if(x[i]==(x[i]+x[j])/2)
					sum--;
				if(x[j]==(x[i]+x[j])/2)
					sum--;
			}
		}
	}
	for(i=1; i<=n; i++)
	{
		sum+=search_hash(x[i], i);
	}
	g<<sum<<"\n";
}