Cod sursa(job #768742)

Utilizator cvicentiuCiorbaru Vicentiu Marian cvicentiu Data 17 iulie 2012 17:28:05
Problema Oite Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.24 kb
#include <stdio.h>
#include <vector>
#include <list>
#define MAXOI 2000
#define MAXH 10007

struct grupare {
	int a, b;
	int sum;
};
using namespace std;

int contains(vector<list<struct grupare> > &hash, int x, int a, int b) {
	list<struct grupare>::iterator it;
	int result = 0;
	int mod = x % MAXH;
	for (it = hash[mod].begin(); it != hash[mod].end(); it++) {
		if ((*it).sum == x && (*it).a != a && (*it).b != a &&
				(*it).a != b && (*it).b != b) {
			result ++;
		}
	}
	return result;
}
int main() {
	int C, L;
	int oi[MAXOI];
	
	int result = 0;
	list<struct grupare> lst;
	vector<list<struct grupare> > hash(MAXH, lst);

	FILE *f = fopen("oite.in", "r");
	FILE *g = fopen("oite.out", "w");

/*	for (int i = 0; i < MAXH; i++) {
		hash.push_back(lst);
	}*/
	fscanf(f, "%d%d", &C, &L);
	for (int i = 0; i < C; i++) {
		fscanf(f, "%d", &oi[i]);
	}

	struct grupare grupa;
	for (int i = 0; i < C; i++) {
		for (int j = i + 1; j < C; j++) {
			grupa.sum = oi[i] + oi[j];
			grupa.a = i;
			grupa.b = j;
			hash[grupa.sum % MAXH].push_back(grupa);
		}
	}

/*	for (int i = 0; i < C; i++) {
		for (int j = i + 1; j < C; j++) {
			int sum = oi[i] + oi[j];
			result += contains(hash, L - sum, i, j);
		}
	}*/
	fprintf(g, "%d", result/4);

	fclose(f);
	fclose(g);


}