## 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

Hisoka
Experienced poster
Posts: 120
Joined: Wed Mar 05, 2003 10:40 am
Location: Indonesia
for another problem if the end of data or process is EOF, you can use that instead of use scan_r.

Good Luck........

29145
New poster
Posts: 3
Joined: Sun Mar 09, 2003 10:29 am
Location: india

### can any one tell me whats wrong

[c]#include<stdio.h>

int main()
{
unsigned long int b[3][3],min,j;
int no ;
while(scanf("%ld %ld %ld %ld %ld %ld %ld %ld %ld",&b[0][0],&b[0][1],&b[0][2],&b[1][0],&b[1][1],&b[1][2],&b[2][0],&b[2][1],&b[2][2]) == 9)

{
j = min = no = 0;
//for bcg
j = b[1][0]+b[2][0] + b[0][2]+b[2][2] + b[0][1]+b[1][1];
min = j;
no = 1;

// for bgc
j = b[1][0]+b[2][0] + b[0][1]+b[2][1] + b[0][2]+b[1][2];
if (j<min)
{
min = j;
no = 2;
}

// for cbg
j = b[1][2]+b[2][2] + b[0][0]+b[2][0] + b[0][1]+b[1][1];
if (j < min )
{
min = j;
no = 3;
}

//for cgb

j = b[1][2]+b[2][2] + b[0][1]+b[2][1] + b[0][0]+b[1][0];
if (j < min )
{
min = j;
no = 4;
}

//for gbc
j = b[1][1]+b[2][1] + b[0][0]+b[2][0] + b[0][2]+b[1][2];
if (j < min )
{
min = j;
no = 5;
}

// for gcb
j = b[1][1]+b[2][1] + b[0][2]+b[2][2] + b[0][0]+b[1][0];
if (j < min )
{
min = j;
no = 6;
}

switch(no)
{
case 1:
printf("BCG %ld",min);
break;
case 2:
printf("BGC %ld",min);
break;

case 3:
printf("CBG %ld",min);
break;

case 4:
printf("CGB %ld",min);
break;

case 5:
printf("GBC %ld",min);
break;

case 6:
printf("GCB %ld",min);
break;
}

}
return 0;
}[/c]

bery olivier
Learning poster
Posts: 90
Joined: Sat Feb 15, 2003 1:39 am
Location: Paris, France
Contact:
I cannot see it on the board, but I suppose you put '\n' in your printfs. Your code seems ok, but for display or scan an unsigned long, you should use "%lu".
Not AC yet AC at last

bery olivier
Learning poster
Posts: 90
Joined: Sat Feb 15, 2003 1:39 am
Location: Paris, France
Contact:
I cannot find anything wrong in your code. I sent it and got AC. Your code is ok.
Not AC yet AC at last

Pier
New poster
Posts: 38
Joined: Thu Mar 27, 2003 9:12 pm
Location: Aguascalientes, Mexico
Contact:

### Help with problem 102!

Hi! Here's my code. Any help aprecciated.

[pascal]Const
l: array [0..2] of char = ('C','B','G');

Var
i,s,tot: Longint;
r: string[3];
n: array [1..9] of longint;

Procedure intenta (a,b,c: longint);
begin
if (n[a]+n+n[c]) > s then
begin
s:= n[a]+n+n[c];
r:= l[a mod 3] + l + l[c mod 3];
end;
end;

Begin
While (not eof(input)) do
begin
tot:= 0; s:= 0;
for i:= 1 to 9 do
begin
Inc(tot, n);
end;
intenta(1,6,8 ); intenta(1,5,9); intenta(3,4,8 );
intenta(3,5,7); intenta(2,4,9); intenta(2,6,7);
writeln(output,r,' ',tot -s);
end;
End.[/pascal]
There are 10 kind of people on this world: those who understand binary and those who don't!

Incognegro
New poster
Posts: 4
Joined: Tue Mar 25, 2003 9:52 pm
You are accumulating larger values of s in intenta as you try out
the different possibilities. I think your mistake is in assuming that
the smallest value for bottle movements is total - the largest value.

Just accumulate on the smallest value instead and forget the
subtraction from total idea.

ben
New poster
Posts: 1
Joined: Mon Apr 14, 2003 12:58 am

### Wierd run time error

****************************************
Your program has died with signal 25 (SIGXFSZ). Meaning:

File size limit exceeded
****************************************
I got above error when I sent problem 102.
I do not know how to ranslate the judge's response
Can some body PLZ help me?
Thanx very much

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:
maybe you try to send file with your program, which exceeds limit ?
(40 kB If I remember ...)
I don't know, which other posibilities could be ...

DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)

soyoja
Experienced poster
Posts: 106
Joined: Sun Feb 17, 2002 2:00 am
Location: Seoul, South Korea
Contact:

### It's one of possible problem...

Because of your mail server system's operations, your mail could be attach dummy code.... I experienced similar case last year.
If your source code seems no problems, then trying online submit or
sending by other mail server.

uvarod
New poster
Posts: 2
Joined: Fri Apr 18, 2003 10:50 pm
Location: Brazil

### No idea to fix 102!!Somebody help, pls!!!

[pascal]
I can
Last edited by uvarod on Sun Apr 20, 2003 4:08 pm, edited 6 times in total.

Eric
Learning poster
Posts: 83
Joined: Wed Sep 11, 2002 6:28 pm
Location: Hong Kong
Oh, I can hardly understand your code.
First, why you output something like 'IVM' other than that given in the question 'BCG'.
Second, how come you compare teo integers?
if b[4]=b[5] or b[6] then
for example, b[5]=30 and b[6]=50
then your code is doing :

Code: Select all

``````b[5]         = 011110
b[6]         = 110010
----------------------------
b[5] or b[6] = 111110 = 63 ?!
``````
Can you see that?

Experienced poster
Posts: 131
Joined: Thu Apr 17, 2003 8:39 am
Location: Baku, Azerbaijan
I have got AC.
This is a very easy problem.
Just check all variations of BCG in a cycle to get the maximum sum of the glasses in bins. And don't forget to choose first in alphabetical order.
Good luck. I hope that it can help you.
_____________
NO sigNature

Experienced poster
Posts: 131
Joined: Thu Apr 17, 2003 8:39 am
Location: Baku, Azerbaijan
The fragment of code:

A is first bin
B is second bin
C is third bin
this is a cycle.
the other part of program you must do yourself

for i:=1 to 3 do
for j:=1 to 3 do
if j<>i then
for k:=1 to 3 do
if (k<>j)and(k<>i) then
if A+B[j]+C[k]>max then

with this I have got AC.

Your program is tooooo long.
_____________
NO sigNature

uvarod
New poster
Posts: 2
Joined: Fri Apr 18, 2003 10:50 pm
Location: Brazil

### Need help 102!!!Somebody say something!!!

[quote]Somebody, please take a look at my code and try give some idea about how to fix it. The trouble is, for example, inputs like 7 8 24 28 42 0 50 19 36 work very well, but some like 50 10 5 20 10 5 10 20 10 don

Eric
Learning poster
Posts: 83
Joined: Wed Sep 11, 2002 6:28 pm
Location: Hong Kong
if b[1]<b[2] and b[3] and b[4] and b[5] and b[6] then
I think what you want to write should be
[pascal]if (b[1]<b[2]) and (b[1]<b[3]) and (b[1]<b[4]) and
(b[1]<b[5]) and (b[1]<b[6]) then[/pascal]
And you need not to have nested if, simply six if statements are enough.
You just need to find the strictly smallest one. Do you see it?