## 102 - Ecological Bin Packing

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

Moderator: Board moderators

supermin
New poster
Posts: 37
Joined: Sat Oct 12, 2002 9:54 am
Location: (Taiwan)
Contact:
Ya....I got accepted message!!!
Thank you very much.!!
I think that my "supposed" test input is too small...right..? ^^"

displesmer
New poster
Posts: 2
Joined: Tue Oct 15, 2002 7:36 am
Contact:
If two or more states result in same minimum movements then alphabetically first string representing a minimal configuration should be printed.
Best Regards
nothing except my mind

Archer
New poster
Posts: 7
Joined: Tue Oct 22, 2002 11:51 pm

### ...

u should reset switcher to zero at the beginning of the while loop, else it will print wrong BGC combinations.

Eric
Learning poster
Posts: 83
Joined: Wed Sep 11, 2002 6:28 pm
Location: Hong Kong

### Alphabetical Order

displesmer wrote:If two or more states result in same minimum movements then alphabetically first string representing a minimal configuration should be printed.
Best Regards
The above algorithm should have already sort the alphabetical order. The problem should be the value of max and initialization.

Axl
New poster
Posts: 2
Joined: Mon Nov 11, 2002 3:56 pm

### prob 102

Wrong Answer: 102
Your program has not solved the problem. It ran during 0.152 seconds.

#include <stdio.h>
unsigned int caixas[9];
int i,menor;
float menora[6];

main()
{
while (scanf("%d %d %d %d %d %d %d %d %d",
&caixas[0],&caixas[1],&caixas[2],
&caixas[3],&caixas[4],&caixas[5],
&caixas[6],&caixas[7],&caixas[8])==9)
{
/*"BCG";*/
menora[0]=caixas[1]+caixas[2]+caixas[3]+caixas[4]+caixas[6]+caixas[8];
/*"BGC";*/
menora[5]=caixas[1]+caixas[2]+caixas[3]+caixas[5]+caixas[6]+caixas[7];
/*"CBG";*/
menora[1]=caixas[0]+caixas[1]+caixas[4]+caixas[5]+caixas[6]+caixas[8];
/*"CGB";*/
menora[4]=caixas[0]+caixas[1]+caixas[3]+caixas[5]+caixas[7]+caixas[8];
/*"GBC";*/
menora[3]=caixas[0]+caixas[2]+caixas[4]+caixas[5]+caixas[6]+caixas[7];
/*"GCB";*/
menora[2]=caixas[0]+caixas[2]+caixas[3]+caixas[4]+caixas[7]+caixas[8];
menor=0;

for (i=1;i<6;i++)
if (menora[menor]>menora[i]) menor=i;
if (menor==0)
printf("BCG %d\n", menora[menor]);
else if (menor==1)
printf("CBG %d\n", menora[menor]);
else if (menor==2)
printf("GCB %d\n", menora[menor]);
else if (menor==3)
printf("GBC %d\n", menora[menor]);
else if (menor==4)
printf("CGB %d\n", menora[menor]);
else if (menor==5)
printf("BGC %d\n,", menora[menor]);
}
}

ashfaq_csdu
New poster
Posts: 4
Joined: Mon Mar 18, 2002 2:00 am

### Re: prob 102

Axl wrote:Wrong Answer: 102
Your program has not solved the problem. It ran during 0.152 seconds.

float menora[6];

if (menor==0)
printf("BCG %d \n", menora[menor]);
The problem is here.
floating numbers but you are using "%d"
use long int instead

ashfaq

Axl
New poster
Posts: 2
Joined: Mon Nov 11, 2002 3:56 pm

### the updated version with the same prob...

#include <stdio.h>
long int caixas[9];
int i,menor;
long int menora[6];

main()
{
while (scanf("%d %d %d %d %d %d %d %d %d",
&caixas[0],&caixas[1],&caixas[2],
&caixas[3],&caixas[4],&caixas[5],
&caixas[6],&caixas[7],&caixas[8])==9)
{
/*"BCG";*/
menora[0]=caixas[1]+caixas[2]+caixas[3]+caixas[4]+caixas[6]+caixas[8];
/*"BGC";*/
menora[5]=caixas[1]+caixas[2]+caixas[3]+caixas[5]+caixas[6]+caixas[7];
/*"CBG";*/
menora[1]=caixas[0]+caixas[1]+caixas[4]+caixas[5]+caixas[6]+caixas[8];
/*"CGB";*/
menora[4]=caixas[0]+caixas[1]+caixas[3]+caixas[5]+caixas[7]+caixas[8];
/*"GBC";*/
menora[3]=caixas[0]+caixas[2]+caixas[4]+caixas[5]+caixas[6]+caixas[7];
/*"GCB";*/
menora[2]=caixas[0]+caixas[2]+caixas[3]+caixas[4]+caixas[7]+caixas[8];

menor=0;

for (i=1;i<6;i++)
if (menora[menor]>menora[i]) menor=i;
if (menor==0)
printf("BCG %d\n", menora[menor]);
else if (menor==1)
printf("CBG %d\n", menora[menor]);
else if (menor==2)
printf("GCB %d\n", menora[menor]);
else if (menor==3)
printf("GBC %d\n", menora[menor]);
else if (menor==4)
printf("CGB %d\n", menora[menor]);
else if (menor==5)
printf("BGC %d\n,", menora[menor]);
}
}

ashfaq_csdu
New poster
Posts: 4
Joined: Mon Mar 18, 2002 2:00 am

### Re: the updated version with the same prob...

Axl wrote:
/*"GBC";*/
menora[3]=caixas[0]+caixas[2]+caixas[4]+caixas[5]+caixas[6]+caixas[7];
/*"GCB";*/
menora[2]=caixas[0]+caixas[2]+caixas[3]+caixas[4]+caixas[7]+caixas[8];
I think the problem is there.
surely GBC comes before GCB. But you wrote menora[3] = GBC
and menora[2] = GCB. As a result GCB comes first.

ashfaq

reyalp
New poster
Posts: 1
Joined: Thu Nov 14, 2002 9:53 pm

### Problem 102

Wrong answer
please advise

#include <iostream>
using namespace std;
unsigned long int input[9];
unsigned long int mini(unsigned long int num[])
{
int i;
unsigned long int min;
min=num[0];
for (i=1;i<7;i++){
if(num<min) min=num;
}
return min;
}
unsigned long int move(int i)
{
switch(i){
case 1: return(input[1]+input[2]); //b1
case 2: return(input[4]+input[5]); //b2
case 3: return(input[7]+input[8]); //b3
case 4: return(input[0]+input[1]); //c1
case 5: return(input[3]+input[4]); //c2
case 6: return(input[6]+input[7]); //c3
case 7: return(input[0]+input[2]); //g1
case 8: return(input[3]+input[5]); //g2
case 9: return(input[6]+input[8]); //g3
}
}
void show(int i)
{

switch(i){
case 1:cout<<"BCG ";break;
case 2:cout<<"BGC ";break;
case 3:cout<<"CBG ";break;
case 4:cout<<"CGB ";break;
case 5:cout<<"GBC ";break;
case 6:cout<<"GCB ";break;
}
}
void main()
{
int i;
unsigned long int min;
unsigned long int num[6];
while(cin>>input[0]>>input[1]>>input[2]>>input[3]>>input[4]>>input[5]>>input[6]>>input[7]>>input[8])
{
num[0]=move(1)+move(5)+move(9);
num[1]=move(1)+move(8 )+move(6);
num[2]=move(4)+move(2)+move(9);
num[3]=move(4)+move(8 )+move(3);
num[4]=move(7)+move(2)+move(6);
num[5]=move(7)+move(5)+move(3);
min=mini(num);
for (i=0;i<=5;i++){
if(num==min){
show(i+1);
cout<<min<<endl;
break;
}
}
}
}

Yes
New poster
Posts: 2
Joined: Sun Nov 17, 2002 5:29 am

### #102

I got WA.
HELP!!

[c]
#include <stdio.h>

int main()
{
int i, j, glass[3][3], sum[7] = {0}, min;

while( scanf( "%d%d%d%d%d%d%d%d%d", &glass[0][0], &glass[0][1],
&glass[0][2], &glass[1][0], &glass[1][1], &glass[1][2],
&glass[2][0], &glass[2][1], &glass[2][2] ) != EOF )
{
sum[0] = 0;

for( i = 0; i < 3; i++ )

for( j = 0; j < 3; j++ )

sum[0] += glass[j];

sum[1] = sum[0] - glass[0][0] - glass[1][1] - glass[2][2];

sum[2] = sum[0] - glass[0][0] - glass[2][1] - glass[1][2];

sum[3] = sum[0] - glass[1][0] - glass[0][1] - glass[2][2];

sum[4] = sum[0] - glass[1][0] - glass[2][1] - glass[0][2];

sum[5] = sum[0] - glass[2][0] - glass[0][1] - glass[1][2];

sum[6] = sum[0] - glass[2][0] - glass[1][1] - glass[0][2];

min = sum[2];

j = 2;

if( sum[1] < min )
{
min = sum[1];

j = 1;
}
if( sum[5] < min )
{
min = sum[5];

j = 5;
}
if( sum[6] < min )
{
min = sum[6];

j = 6;
}
if( sum[3] < min )
{
min = sum[3];

j = 3;
}
if( sum[4] < min )
{
min = sum[4];

j = 4;
}
switch( j )
{
case 1:

printf( "BGC" );

break;

case 2:

printf( "BCG" );

break;

case 3:

printf( "GBC" );

break;

case 4:

printf( "CBG" );

break;

case 5:

printf( "GCB" );

break;

case 6:

printf( "CGB" );

break;

default:

break;
}
printf( " %d\n", min );
}
return 0;
}
[/c]

Haomiao
New poster
Posts: 5
Joined: Sat Nov 16, 2002 11:28 am
Location: Xi'an,China
Contact:

### something about 102...

method...
who can tell me...
a bit of thanks...

ezra
New poster
Posts: 31
Joined: Thu Nov 21, 2002 2:11 pm
you got integer overflow because the total number of botlle reached 2^31.
Read the problem once again.

Yes
New poster
Posts: 2
Joined: Sun Nov 17, 2002 5:29 am
I still got WA even if I use "long long"

Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:
Try all combinations, there's only a few of them.

Balon
New poster
Posts: 8
Joined: Tue Nov 26, 2002 6:00 am
dear comrade Hao,
You can use 3 nesting for() loop, soooooooooo easy, isn't it
If you still don't know how to do it , you can ask Balon Fan directly, HenHenHen