11005 - Cheapest Base

All about problems in Volume 110. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
Soarer
New poster
Posts: 14
Joined: Wed Nov 09, 2005 8:17 pm

11005 - Cheapest Base

Post by Soarer »

I tried four times and I still get a presentation error... please help!

Code: Select all

CODE REMOVED
Last edited by Soarer on Sun Mar 26, 2006 1:09 pm, edited 1 time in total.
Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Post by Darko »

Problem statement:
Print a blank line between cases.
Not "after each case"

Darko
Soarer
New poster
Posts: 14
Joined: Wed Nov 09, 2005 8:17 pm

Post by Soarer »

Thanks!
Gaizka
New poster
Posts: 7
Joined: Wed May 24, 2006 12:37 am

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

Post 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.!
Last edited by Gaizka on Mon May 29, 2006 10:13 pm, edited 1 time in total.
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

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

Post 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.
Gaizka
New poster
Posts: 7
Joined: Wed May 24, 2006 12:37 am

Post 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.
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Post 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.
Mata
New poster
Posts: 18
Joined: Mon Dec 17, 2007 11:35 pm
Location: Queretaro
Contact:

Re: 11005 - Cheapest Base

Post 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;
}

/********************************
********************************/
Post Reply

Return to “Volume 110 (11000-11099)”