10365 - Blocks

All about problems in Volume 103. 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
negue
New poster
Posts: 6
Joined: Tue Sep 24, 2002 8:00 pm
Location: Iasi, Romania

10365 - Blocks

Post by negue »

I don't understand the output / the problem:
-for 5 there is no answer
-for 10 we can find a box of 2*2*3 inches and so the area is 2*(2*2+2*3+2*3)=32<34
- 26 blocks fit in the solid that contains 27 blocks (area[26]<area[27]) but 82>54.
It seems I don't understand what a solid rectangular means or what area is about.
Please explain! Thanks!

arc16
Learning poster
Posts: 62
Joined: Sun Aug 04, 2002 1:05 am
Location: Indonesia

Post by arc16 »

i think you misunderstood the problem :)
first, 5 is the number of test case...
2nd, for 10 blocks, the possible arrangement is 1*1*10 or 1*2*5.
that goes to 26 blocks, which have possible arrangement of 1*1*26 or 1*2*13. For 27 blocks, the possible arrangement is 1*1*27, 1*3*9, and 3*3*3. For each possible arrangement, you have to calculate the wrapping area and find the minimum result.
if you still confused, think about a box which has the volume of n inches^3. Then you have to find the possible height,length, and width of the box which will make an n inches^3 box. (v = h*l*w)
good luck :lol:

Algoritmo
New poster
Posts: 32
Joined: Wed Oct 15, 2003 12:10 pm
Contact:

Finding the factors

Post by Algoritmo »

I got correct answers for sample input but got WA after submission of code.

To find the dimensions of the stack of blocks, I factored the number of blocks with this goal:
F1 * F2 * F3 = Blocks
F1 + F2 + F3 -->> the smallest possible

I used this procedure to find F1, F2 and F3:
Num = Blocks
for n = 1 to 3
..Fn is the biggest number in this range: 1 <= Fn^n <= Num
..Num = Num / Fn
end for
Is my procedure always correct ?

My input:
10
9
10
26
27
100
0
1
17
9999
10000

My output:
30
34
82
54
130
0
6
70
4238
2800
I solve 4 problems per day, then I expend 4 days stuck in a single problem. But I think I'm doing well... ID 37180

ranjit
New poster
Posts: 34
Joined: Fri Jan 30, 2004 11:22 am
Location: india

check for proper primality tests

Post by ranjit »

what is your output for 1 and 2?
maybe it is helpful.

best of luck.

dipaly
New poster
Posts: 20
Joined: Tue Sep 19, 2006 6:18 pm
Location: bangladesh
Contact:

Post by dipaly »

hi i am getting wa in this problem
To find smallest (h+l+w) i do ................ like this

Code: Select all

long h=1,l=n,w=1;
				double d = pow(n,1.0/3.0);
				
				for (long i = d ; i>1 ;i--)
				{
					if(n%i==0)
					{
						h=i;l=n/i;
						break;
					}
				}
				
				for (long i = sqrt(l) ; i>1 ;i--)
				{
					if(l%i==0)
					{
						w=i;l=l/i;
						break;
					}
				}
is this correct ?????????
plz give some hints...or more test case

any way here is my code

Code: Select all

#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int main()
{
	long t;
	while(scanf("%ld",&t)==1)
	{
		for(int j = 0; j< t ;j++)
		{
			long n ;
			scanf("%ld",&n);
			if(n==0)
				printf("0\n");
			else 
			{	 
				long h=1,l=n,w=1;
				double d = pow(n,1.0/3.0);
				
				for (long i = d ; i>1 ;i--)
				{
					if(n%i==0)
					{
						h=i;l=n/i;
						break;
					}
				}
				
				for (long i = sqrt(l) ; i>1 ;i--)
				{
					if(l%i==0)
					{
						w=i;l=l/i;
						break;
					}
				}
				//printf("%ld %ld %ld %lf\n",a,b,c,d);
				long r;
				r = h*l*2 + h*w*2 + l*w*2;
					
				printf("%ld\n",r);
			}
		}
	}
	return 0;
}


thanks in adv...
everything is so hard to me

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Try the cases.

Input:

Code: Select all

3
64
68
76
Output:

Code: Select all

96
144
160
And just asking..

Code: Select all

while(scanf("%ld",&t)==1)
Is it necessary? You can replace it with

Code: Select all

scanf("%ld",&t);
However both should be correct.

Hope these help.
Ami ekhono shopno dekhi...
HomePage

dipaly
New poster
Posts: 20
Joined: Tue Sep 19, 2006 6:18 pm
Location: bangladesh
Contact:

Post by dipaly »

thanks for help ...... :)
i modify my code .... but still wa :( is my process correct to compute smallest (h+l+w) ?????????????

here is my modifing code

Code: Select all

#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int main()
{
	long t;
	while(scanf("%ld",&t)==1)
	{
		for(int j = 0; j< t ;j++)
		{
			long n ;
			scanf("%ld",&n);
			if(n==0)
				printf("0\n");
			else 
			{	 
				long h=1,l=n,w=1,d,h2,l2,w2;
				for (long i =1 ; i*i*i<=n ;i++)
					d=i;

				
				for (long i =d ; i>1 ;i--)
				{
					if(n%i==0)
					{
						h=i;l=n/i;
						break;
					}
				}
				l2=l;
				for (long i = sqrt(l) ; i>1 ;i--)
				{
					if(l%i==0)
					{
						w=i;l=l/i;
						break;
					}
				}
				for (long i = sqrt(h) ; i>1 ;i--)
				{
					if(h%i==0)
					{
						w2=i;h2=h/i;
						break;
					}
				}
				
				
				long r1,r2;
				r1 = h*l*2 + h*w*2 + l*w*2;
				r2 = h2*l2*2 + h2*w2*2 + l2*w2*2;	
				if(r1>r2)
				printf("%ld\n",r2);
				else 
				printf("%ld\n",r1); 
			}
		}
	}
	return 0;
}

thankxxxx again
everything is so hard to me

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Try n=1 to 10. I don't think your method is correct.

I actually tried all possible ways and picked the best option.
Ami ekhono shopno dekhi...
HomePage

Post Reply

Return to “Volume 103 (10300-10399)”