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

midra
Experienced poster
Posts: 119
Joined: Fri Feb 13, 2004 7:20 am
Contact:

Post by midra » Wed Feb 18, 2004 2:12 am

thank you so much for answer me!!!!!!!! :D :D :D
I have changed the scanf for this:

[c]
while(scanf("%ld %ld %ld %ld %ld %ld %ld %ld %ld", &brown[0], &green[0], &clear[0], &brown[1], &green[1], &clear[1], &brown[2], &green[2], &clear[2])!=EOF)
[/c]

but I got WA
My idea is to got AC with my own code, if you got AC and can pass me your code, ok then, but I am so bad understanding codes, I always gets confused with simple codes


sorry my english but I am from Argentina

Sayutee
New poster
Posts: 9
Joined: Wed Jun 04, 2003 7:50 am
Location: Bangladesh

Post by Sayutee » Wed Feb 18, 2004 6:43 pm

I cant spend much time to understand your code online(charge for using internet is a little high here) but one small thing - u have used a 3 element array to store the combination. But shouldn't it be that "BCG" needs a 4 element array to store its terminating NULL?

Your English is not too bad - there is no need to be ashamed of it! I will copy and examine your code and will try to make any suggestions if i can (It is a very good and appreciable idea to get AC with your own code.)

midra
Experienced poster
Posts: 119
Joined: Fri Feb 13, 2004 7:20 am
Contact:

Post by midra » Thu Feb 19, 2004 2:09 am

thanks a lot!
don't spend time!!it doesn't care!!
I would think it by myself!!!
good luck!!ByEEE

Sayutee
New poster
Posts: 9
Joined: Wed Jun 04, 2003 7:50 am
Location: Bangladesh

Post by Sayutee » Thu Feb 19, 2004 6:47 am

Not at all - it is always a pleasure to be able to help anyone!

I have run your code - you have two major faults!

First - you have to store the configurations ("BCG" etc) in a 4 element character array. When I run the code, i got this output BCGA 30. Remember, in C or C++, you have to use one extra byte at the last of the array to store the terminating NULL value.

Second - You have to process all inputs - but you forgot to use the braces { and } after while statement - your programme just reads in the last line of input. Use a opening brace - { - just after while and a closing brace - } - just after printf and before return. I found no other mistake. Hope this will solve your problem.

You also forgot to include string.h for string functions!

I think you are a newcomer here. not a matter. I feel greatly delighted if i become able to help someone (i am not a good programmer myself :)) However - if you want to contact me on anything on ptogramming, you can use sayutee1011@yahoo.com. I will be glad to hear from you.

Best of Luck.[/b]

rubendv
New poster
Posts: 9
Joined: Mon Mar 15, 2004 10:23 pm

Problem 102. I can't figure why the WA. HELP

Post by rubendv » Mon Mar 15, 2004 10:26 pm

#include <stdio.h>
#include <string.h>



#define LIM (9)



unsigned long costs[LIM / 3 + 3];

unsigned long bin[LIM];

char first, second, third;



void countMoves(void){

costs[0] = bin[1] + bin[2] + bin[3] + bin[4] + bin[6] + bin[8]; /* BCG */

costs[1] = bin[1] + bin[2] + bin[3] + bin[5] + bin[6] + bin[7]; /* BGC */

costs[2] = bin[0] + bin[2] + bin[4] + bin[5] + bin[6] + bin[7]; /* GBC */

costs[3] = bin[0] + bin[2] + bin[3] + bin[4] + bin[7] + bin[8]; /* GCB */

costs[4] = bin[0] + bin[1] + bin[4] + bin[5] + bin[6] + bin[8]; /* CBG */

costs[5] = bin[0] + bin[1] + bin[3] + bin[5] + bin[7] + bin[8]; /* CGB */

}


void decide(void){

int theCase = 0, i;

printf("%ld", costs[0]);

for (i = 1; i < 6; i++){
printf(" %ld", costs);

if (costs < costs[theCase])

theCase = i;
}
printf("\n");

if (theCase == 0)

printf("BCG ");

else if (theCase == 1)

printf("BGC ");

else if (theCase == 2)

printf("GBC ");

else if (theCase == 3)

printf("GCB ");

else if (theCase == 4)

printf("CBG ");

else if (theCase == 5)

printf("CGB ");

printf("%ld\n", costs[theCase]);

}


int main(void){

int i;

while (1){

for (i = 0; i < 9; i++){

if (scanf("%ld", &bin) < 1)

return 0;

}

memset(costs, -1, sizeof(costs));

countMoves();

decide();

}

}

[c][/c]

User avatar
Chung Ha, Yun
New poster
Posts: 19
Joined: Tue Jul 16, 2002 5:56 pm
Location: Seoul
Contact:

^_^

Post by Chung Ha, Yun » Tue Mar 16, 2004 2:21 am

If more than one order of brown, green, and clear bins yields the minimum number of movements then the alphabetically first string representing a minimal configuration should be printed.
BCG
BGC
GBC
GCB
CBG
CGB

is not alphabetically order.

HerrAachen
New poster
Posts: 12
Joined: Sat Apr 03, 2004 11:01 pm

Post by HerrAachen » Sun Apr 04, 2004 4:33 pm

why do i get WA on this?? I've tried the two examples and everything. In my view it works.

Code: Select all

#include <stdio.h>
void main()
{
int b1,b2,b3,
    g1,g2,g3,
    c1,c2,c3,
    transfers,
    tmp;
char sol[3];

while(scanf("%d %d %d %d %d %d %d %d %d",&b1,&g1,&c1,&b2,&g2,&c2,&b3,&g3,&c3)==9)
   {
   transfers=b2+b3+c1+c3+g1+g2;
   sol[0]='B';sol[1]='C';sol[2]='G';
   tmp=b2+b3+g1+g3+c1+c2;
   if (tmp<transfers){sol[0]='B';sol[1]='G';sol[2]='C';transfers=tmp;}
   tmp=c2+c3+b1+b3+g1+g2;
   if (tmp<transfers){sol[0]='C';sol[1]='B';sol[2]='G';transfers=tmp;}
   tmp=c2+c3+g1+g3+b1+b2;
   if (tmp<transfers){sol[0]='C';sol[1]='G';sol[2]='B';transfers=tmp;}
   tmp=g2+g3+b1+b3+c1+c2;
   if (tmp<transfers){sol[0]='B';sol[1]='B';sol[2]='C';transfers=tmp;}
   tmp=g2+g3+c1+c3+b1+b2;
   if (tmp<transfers){sol[0]='G';sol[1]='C';sol[2]='B';transfers=tmp;}
   printf("%c%c%c %d\n",sol[0],sol[1],sol[2],transfers);
   }
}

HerrAachen
New poster
Posts: 12
Joined: Sat Apr 03, 2004 11:01 pm

Post by HerrAachen » Sun Apr 04, 2004 4:45 pm

hope this has a more comfortable colour:

[cpp]#include <stdio.h>
void main()
{
int b1,b2,b3,
g1,g2,g3,
c1,c2,c3,
transfers,
tmp;
char sol[3];

while(scanf("%d %d %d %d %d %d %d %d %d",&b1,&g1,&c1,&b2,&g2,&c2,&b3,&g3,&c3)==9)
{
transfers=b2+b3+c1+c3+g1+g2;
sol[0]='B';sol[1]='C';sol[2]='G';
tmp=b2+b3+g1+g3+c1+c2;
if (tmp<transfers){sol[0]='B';sol[1]='G';sol[2]='C';transfers=tmp;}
tmp=c2+c3+b1+b3+g1+g2;
if (tmp<transfers){sol[0]='C';sol[1]='B';sol[2]='G';transfers=tmp;}
tmp=c2+c3+g1+g3+b1+b2;
if (tmp<transfers){sol[0]='C';sol[1]='G';sol[2]='B';transfers=tmp;}
tmp=g2+g3+b1+b3+c1+c2;
if (tmp<transfers){sol[0]='B';sol[1]='B';sol[2]='C';transfers=tmp;}
tmp=g2+g3+c1+c3+b1+b2;
if (tmp<transfers){sol[0]='G';sol[1]='C';sol[2]='B';transfers=tmp;}
printf("%c%c%c %d\n",sol[0],sol[1],sol[2],transfers);
}
}[/cpp]

prince56k
New poster
Posts: 33
Joined: Fri Dec 12, 2003 10:32 pm
Location: BANGLADESH

Post by prince56k » Mon Apr 12, 2004 10:09 pm

Hi HerrAachen,

In your fourth If condition u just print BBC :wink:

Hope it helps u. More over, u have declared your variable as int and the max input could be 2^31-1 . so pease use c++ compiler while submission on unsigned long incase of C compiler.

Qbens
New poster
Posts: 5
Joined: Fri Apr 23, 2004 11:37 pm
Location: Poland
Contact:

Compile Error: 102

Post by Qbens » Sat Apr 24, 2004 1:52 pm

Can someone tell my what is wrong with my code:
[cpp]
#include <stdio.h>

int main(void)
{
long green[3],clear[3],brown[3];
long temp[6];
char letters[19]={"BCGBGCCBGCGBGBCGCB"};

while(scanf("%D %D %D %D %D %D %D %D %D",&brown[0],
&green[0],&clear[0],&brown[1],&green[1],
&clear[1],&brown[2],&green[2],&clear[2])==9){

temp[0]=brown[1]+brown[2] + clear[0]+clear[2] + green[0]+green[1]; /*BCG*/
temp[1]=brown[1]+brown[2] + green[0]+green[2] + clear[0]+clear[1]; /*BGC*/
temp[2]=clear[1]+clear[2] + brown[0]+brown[2] + green[0]+green[1]; /*CBG*/
temp[3]=clear[1]+clear[2] + green[0]+green[2] + brown[0]+brown[1]; /*CGB*/
temp[4]=green[1]+green[2] + brown[0]+brown[2] + clear[0]+clear[1]; /*GBC*/
temp[5]=green[1]+green[2] + clear[0]+clear[2] + brown[0]+brown[1]; /*GCB*/

int index=0;

for(int n=1; n<6; n++)
{
if(temp[n]<temp[index]) index=n;
}

for(int p=3*index; p<3+(3*index); p++)
{
printf("%c",letters[p]);
}
printf(" %D\n",temp[index]);
}/*end of while*/
return 0;
}
[/cpp]

I received Compile Error

User avatar
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Post by sohel » Sat Apr 24, 2004 2:05 pm

I submitted your code and the reply was wrong answer -- not compile error.

Mention , how you are submitting the probem ? :-?

Qbens
New poster
Posts: 5
Joined: Fri Apr 23, 2004 11:37 pm
Location: Poland
Contact:

Post by Qbens » Sat Apr 24, 2004 2:20 pm

I submited it via E-Mail. It is what I sent:
[cpp]
/* @JUDGE_ID: MY_ID 102 C */

@BEGIN_OF_SOURCE_CODE
/*******************
Solution to problem "Ecological Bin Packing" Volume I 102
Author: Qbens kuba_sko@tlen.pl
date 22/04/2004
*******************/

#include <stdio.h>

int main(void)
{
long green[3],clear[3],brown[3];
long temp[6];
char letters[19]={"BCGBGCCBGCGBGBCGCB"};

while(scanf("%D %D %D %D %D %D %D %D %D",&brown[0],
&green[0],&clear[0],&brown[1],&green[1],
&clear[1],&brown[2],&green[2],&clear[2])==9){

temp[0]=brown[1]+brown[2] + clear[0]+clear[2] + green[0]+green[1]; /*BCG*/
temp[1]=brown[1]+brown[2] + green[0]+green[2] + clear[0]+clear[1]; /*BGC*/
temp[2]=clear[1]+clear[2] + brown[0]+brown[2] + green[0]+green[1]; /*CBG*/
temp[3]=clear[1]+clear[2] + green[0]+green[2] + brown[0]+brown[1]; /*CGB*/
temp[4]=green[1]+green[2] + brown[0]+brown[2] + clear[0]+clear[1]; /*GBC*/
temp[5]=green[1]+green[2] + clear[0]+clear[2] + brown[0]+brown[1]; /*GCB*/

int index=0;

for(int n=1; n<6; n++)
{
if(temp[n]<temp[index]) index=n;
}

for(int p=3*index; p<3+(3*index); p++)
{
printf("%c",letters[p]);
}
printf(" %D\n",temp[index]);
}/*end of while*/
return 0;
}
@END_OF_SOURCE_CODE
[/cpp]

compiler error messages:
02481154_24.c: In function `main':
02481154_24.c:26: parse error before `int'
02481154_24.c:28: parse error before `int'
02481154_24.c:28: `n' undeclared (first use in this function)
02481154_24.c:28: (Each undeclared identifier is reported only once
02481154_24.c:28: for each function it appears in.)
02481154_24.c:28: parse error before `)'
02481154_24.c:33: parse error before `int'
02481154_24.c:33: `p' undeclared (first use in this function)
02481154_24.c:33: `index' undeclared (first use in this function)
02481154_24.c:33: parse error before `)'
02481154_24.c: At top level:
02481154_24.c:37: parse error before string constant
02481154_24.c:37: warning: data definition has no type or storage class

anupam
A great helper
Posts: 405
Joined: Wed Aug 28, 2002 6:45 pm
Contact:

Post by anupam » Sat Apr 24, 2004 5:33 pm

Qbens wrote:I submited it via E-Mail. It is what I sent:
[cpp]
/* @JUDGE_ID: MY_ID 102 C */
>>>/*@begin_of--...*/
@BEGIN_OF_SOURCE_CODE




int index=0;
>>int n; for(n=1...
for(int n=1; n<6; n++)
{
if(temp[n]<temp[index]) index=n;
}
>>here again
for(int p=3*index; p<3+(3*index); p++)
{
printf("%c",letters[p]);
}
printf(" %D\n",temp[index]);
}/*end of while*/
return 0;
}
>>/*end_of_...*/
@END_OF_SOURCE_CODE
[/cpp]

compiler error messages:
02481154_24.c: In function `main':
02481154_24.c:26: parse error before `int'
02481154_24.c:28: parse error before `int'
02481154_24.c:28: `n' undeclared (first use in this function)
02481154_24.c:28: (Each undeclared identifier is reported only once
02481154_24.c:28: for each function it appears in.)
02481154_24.c:28: parse error before `)'
02481154_24.c:33: parse error before `int'
02481154_24.c:33: `p' undeclared (first use in this function)
02481154_24.c:33: `index' undeclared (first use in this function)
02481154_24.c:33: parse error before `)'
02481154_24.c: At top level:
02481154_24.c:37: parse error before string constant
02481154_24.c:37: warning: data definition has no type or storage class
"Everything should be made simple, but not always simpler"

Almost Human
Learning poster
Posts: 93
Joined: Sun Jan 12, 2003 3:30 pm

Post by Almost Human » Tue Apr 27, 2004 7:50 am

I guess the problem is you send the problem as C source code.

In C, we can only declare variable on the top of scope A, so doing this :

for ( int i = 0 ; ... bla bla bla

would be illegal ..

hope it helps

HerrAachen
New poster
Posts: 12
Joined: Sat Apr 03, 2004 11:01 pm

Post by HerrAachen » Sat May 01, 2004 12:06 am

ya I got this BBC-thing figured already. Sorry for using you as a debugger. The integer range didn't seem to be a problem. I got accepted wit this.

Post Reply

Return to “Volume 1 (100-199)”