Page 1 of 1

11005 - Cheapest Base

Posted: Sun Mar 26, 2006 10:40 am
by Soarer
I tried four times and I still get a presentation error... please help!

Code: Select all

CODE REMOVED

Posted: Sun Mar 26, 2006 12:03 pm
by Darko
Problem statement:
Print a blank line between cases.
Not "after each case"

Darko

Posted: Sun Mar 26, 2006 1:09 pm
by Soarer
Thanks!

Why doesn't it work!?!?!?

Posted: Wed May 24, 2006 12:41 am
by Gaizka
Well, this is my first algorithm but for some reason the server doesn't accept it, i've tried it myself and works perfect, please help me!!! I've tried like a million times.!

Re: Why doesn't it work!?!?!?

Posted: Sun May 28, 2006 8:32 pm
by Martin Macko
Gaizka wrote:

Code: Select all

int main(int argc, char *argv[]){
    int cases;
    int* query=new int[cases];
    int** numbers=new int*[cases];
    int** values=new int*[cases];
    cin >> cases;
    ....
}
The quoted lines look a bit strange as cases is not initialised before constructing the arrays.

Posted: Sun May 28, 2006 8:50 pm
by Gaizka
Well, I solved it. It was not the cases thing. 'though it was wrong.

The problem was that i was validating the input with the information from the problem. But we don't have to do that. It's weird.

Posted: Sun May 28, 2006 8:58 pm
by Martin Macko
Gaizka wrote:Well, I solved it. It was not the cases thing. 'though it was wrong.
Great :)
As your problem is solved, please, in order to not have spoilers here, remove the code from your previous post.

Re: 11005 - Cheapest Base

Posted: Thu Jun 26, 2008 7:30 pm
by Mata
Hi, i try this problem but i get wrong answer, i think its an easy problem but i cant find my mistake, can someone give some test input to see what its wrong with my code?, this is what i do:

Code: Select all

#include <iostream>
#define S 36
void inicio(int a[], int n);
int menorCosto(int a[]);
int costoN(int n, int base, int costo[]);
int main()
{
	int casos=0, c=0;
	int *costo, *base;
	costo=new int[S];
	base=new int[S];
	scanf("%d",&casos);
	while(casos>0)
	{
		c++;
		printf("Case %d:\n",c);
		inicio(costo,S);
		int x=0, querys=0;
		while(x<S)
		{
			scanf("%d",&costo[x]);
			x++;
		}
		x=0;
		scanf("%d",&querys);
		while(querys>0)
		{
			int n=0, menor=0;
			scanf("%d",&n);
			printf("Cheapest base(s) for number %d:",n);
			x=1;
			inicio(base,S);
			while(x<S)
			{
				x++;
				base[x]=costoN(n,x,costo);
			}
			menor=menorCosto(base);
			x=1;
			while(x<S)
			{
				x++;
				if(base[x]==menor)
					printf(" %d",x);
			}
			querys--;
			if(querys>0)
				printf("\n");
		}
		casos--;
		if(casos>0)
			printf("\n\n");
	}
	return 0;
}
int costoN(int n, int base, int c[])
{
	int s=0;
	while(n>0)
	{
		s+=c[n%base];
		n/=base;
	}
	return s;
}
void inicio(int a[], int n)
{
	while(n>=0)
	{
		a[n]=0;
		n--;
	}
}
int menorCosto(int a[])
{
	int x=2, c=-1;
	while(x<S)
	{
		if(a[x]<c||c==-1)
			c=a[x];
		x++;
	}
	return c;
}