Cod sursa(job #436898)

Utilizator Bogdan.CirsteaCirstea Bogdan-Ionut Bogdan.Cirstea Data 9 aprilie 2010 00:45:08
Problema Gutui Scor 0
Compilator c Status done
Runda teme_upb Marime 1.59 kb
#include <stdio.h>
#include <string.h>
#include <stdlib.h> 

//se scade din inaltimea maxima si se compara cu restul
typedef struct gutui_aux
{
int inaltime;
int valoare;
}
structuraGutui;

int comparator(const void* gutuie1, const void* gutuie2)
{
	return (*(structuraGutui*)gutuie2).inaltime - (*(structuraGutui*)gutuie1).inaltime;
}

int max(int a, int b)
{
	if (a > b) return a;
	else return b;
}

int profit(structuraGutui gutui[], int i, int n, int inaltime, int pas)
{
	return 0;

	if ((i < n) && (inaltime > 0) && (gutui[i].inaltime <= inaltime))
		return max( (profit(gutui, i+1, n, inaltime - pas, pas) + gutui[i].valoare),
			    profit(gutui, i+1, n, inaltime, pas) );

	if ((i < n) && (inaltime > 0) && (gutui[i].inaltime > inaltime))
		return profit(gutui, i+1, n, inaltime, pas);

	//if (inaltime <= 0 || i >= n)
		return 0;
}

int main()
{
	int fd1,fd2;
	
	fd1=fopen("gutui.out", "w");
	fd2=fopen("gutui.in", "r");

	int numarGutui, height, step;
	fscanf(fd2, "%i %i %i", &numarGutui, &height, &step);
	//printf("Gutui: %i; Inaltime: %i; Step: %i \n", numarGutui, height, step);

	//SAU STRUCTURA - > MAI NATURAL
	structuraGutui gutui[numarGutui]; 
	int i;
	for (i = 0; i < numarGutui; i++)
		fscanf(fd2, "%i %i ", &(gutui[i].inaltime), &(gutui[i].valoare));
	
	qsort(gutui, numarGutui, sizeof(gutui[0]), comparator);
		
	//for (i = 0; i < numarGutui; i++)
	//	printf( "%i %i \n", gutui[i].inaltime, gutui[i].valoare);

	//printf("Profit: %i \n", profit(gutui, 0, numarGutui, height, step));
	fprintf(fd1, "%i ", profit(gutui, 0, numarGutui, height, step));

	fclose(fd2);	
	fclose(fd1);
	
	return 0;
	
}