Cod sursa(job #768774)

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

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

int contains(vector<vector<struct grupare> > &hash, int x, int a, int b) {
	vector<struct grupare>::iterator it;
	int result = 0;
	
	for (it = hash[x % MAXH].begin(); it != hash[x % MAXH].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;
	vector<struct grupare> lst;
	vector<vector<struct grupare> > hash;

	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];
			if (L - sum > 0) {
				vector<struct grupare>::iterator it;	
				int x = L - sum;
				int mod = x % MAXH;
				for (it = hash[mod].begin(); it != hash[x % MAXH].end(); it++) {
					if ((*it).sum == x && (*it).a != i && (*it).b != i &&
							(*it).a != j && (*it).b != j) {
						result ++;
					}
				}
			}
		}
	}
	*/
	fprintf(g, "%d", result / 6);

	fclose(f);
	fclose(g);


}