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

sumankar
A great helper
Posts: 286
Joined: Tue Mar 25, 2003 8:36 am
Location: calcutta
Contact:

Re: 102 help me always "Compile error"

Post by sumankar »

chiunyao wrote:

Code: Select all

for(int k=0;k<6;k++) 
That is not supported by the C language version judge's gcc takes in. Put the

Code: Select all

int k;
part somewhere at the top where you declare your variables and see if it works or not.
chiunyao
New poster
Posts: 4
Joined: Mon Feb 13, 2006 11:07 am

Post by chiunyao »

Thanks for you help me to find the error,i have'd correct my code,
but i submitted my answer also get "wrong answer",i don't why?

Please help me thanks :)

Code: Select all

#include <stdio.h> 
int main(void) 
{ 
	 long int a[9]; 
	 long int b[6]; 
	 long int MIN=2147483647;
	 int MINNUM; 
	 int k;

	while(scanf("%ld%ld%ld%ld%ld%ld%ld%ld%ld", &a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &a[6], &a[7], &a[8]) == 9) 
	{ 
		


	b[1]=a[3]+a[6]+a[1]+a[7]+a[2]+a[5]; 
	b[0]=a[3]+a[6]+a[2]+a[8]+a[1]+a[4]; 
	b[4]=a[4]+a[7]+a[0]+a[6]+a[2]+a[5]; 
	b[5]=a[4]+a[7]+a[2]+a[8]+a[0]+a[3]; 
	b[2]=a[5]+a[8]+a[0]+a[6]+a[1]+a[4]; 
	b[3]=a[5]+a[8]+a[1]+a[7]+a[0]+a[3]; 


	for(k=0;k<6;k++) 
	{ 

		if(b[k]<MIN) 
		{ 
			MIN=b[k]; 
			MINNUM=k; 
		} 
	} 
		if(MINNUM==0) 
		printf("BCG %ld\n",b[0]);
	else if(MINNUM==1)
		printf("BGC %ld\n",b[1]);
	else if(MINNUM==2) 
		printf("CBG %ld\n",b[2]);
	else if(MINNUM==3)
		printf("CGB %ld\n",b[3]);
	else if(MINNUM==4)
		printf("GBC %ld\n",b[4]);
	else if (MINNUM==5)
		printf("GCB %ld\n",b[5]);
	 	} 
return 0; 
} 
IRA
Learning poster
Posts: 82
Joined: Sat Jan 07, 2006 6:52 am

Post by IRA »

I add one line code and got AC.....

Code: Select all

#include <stdio.h> 
int main(void) 
{ 
    long int a[9]; 
    long int b[6]; 
    long int MIN=2147483647; 
    int MINNUM; 
    int k; 

   while(scanf("%ld %ld %ld %ld %ld %ld %ld %ld %ld", &a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &a[6], &a[7], &a[8]) == 9) 
   { 
       

	MIN=2147483647;/////////////////////////// Becareful to reset ///////////////
   b[1]=a[3]+a[6]+a[1]+a[7]+a[2]+a[5]; 
   b[0]=a[3]+a[6]+a[2]+a[8]+a[1]+a[4]; 
   b[4]=a[4]+a[7]+a[0]+a[6]+a[2]+a[5]; 
   b[5]=a[4]+a[7]+a[2]+a[8]+a[0]+a[3]; 
   b[2]=a[5]+a[8]+a[0]+a[6]+a[1]+a[4]; 
   b[3]=a[5]+a[8]+a[1]+a[7]+a[0]+a[3]; 


   for(k=0;k<6;k++) 
   { 

      if(b[k]<MIN) 
      { 
         MIN=b[k]; 
         MINNUM=k; 
      } 
   } 
      if(MINNUM==0) 
      printf("BCG %ld\n",b[0]); 
   else if(MINNUM==1) 
      printf("BGC %ld\n",b[1]); 
   else if(MINNUM==2) 
      printf("CBG %ld\n",b[2]); 
   else if(MINNUM==3) 
      printf("CGB %ld\n",b[3]); 
   else if(MINNUM==4) 
      printf("GBC %ld\n",b[4]); 
   else if (MINNUM==5) 
      printf("GCB %ld\n",b[5]); 
       } 
return 0; 
} 
sds1100
Learning poster
Posts: 95
Joined: Sat Dec 10, 2005 2:09 pm

sorry i don't know your program..

Post by sds1100 »

sorry i don't know your program..
sorry.sorry.sorry.sorry.sorry.
Rulojuka
New poster
Posts: 2
Joined: Sun Mar 26, 2006 8:21 am
Location: Brasil - SP

Why don't i get Accepted in 102?

Post by Rulojuka »

I'm trying to solve the problem 102 and I am having a problem.

I think my program is right, giving the correct answer in a good time without too much memory but i just get WA.

Please someone help me, this is the input that im testing:

1 2 3 4 5 6 7 8 9
5 10 5 20 10 5 10 20 10
0 0 0 0 0 0 0 0 2147483648
2147483648 0 0 0 0 0 0 0 0
0 2147483648 0 0 0 0 0 0 0
0 0 2147483648 0 0 0 0 0 0
1 2 3 4 5 6 7 8 9
1000 200 1500 350 5000 1000 1000 2000 13000
5 10 5 20 10 5 10 20 10
60 20 1000 1000 60 20 10000 20 500
20 1000 50 2000 50 500 1500 20 3000
20 1000 50 2000 50 5000 1500 20 300

and this is the output:

BCG 30
CBG 50
BCG 0
BCG 0
GBC 0
CBG 0
BCG 30
BCG 6050
CBG 50
CGB 1620
GBC 2140
GCB 2440

Can anyone tell me what is wrong with it?
Rulojuka
New poster
Posts: 2
Joined: Sun Mar 26, 2006 8:21 am
Location: Brasil - SP

Final Sort Error

Post by Rulojuka »

I ve got AC.

I thought the final output should be in the order BGC,BCG,GBC...CGB, but its alphabetically... but now the problem is ok.
xopht
New poster
Posts: 1
Joined: Mon Apr 17, 2006 10:10 am

102 - WA

Post by xopht »

Could you please tell me what problem is on my code?

Code: Select all

#include <iostream>
#include <string>

using namespace std;

int take( int n, string* str, int* b, int sum )
{
    switch( n )
    {
        case 1:
            *str    = "BGC";
            return sum - b[ 0 ] - b[ 4 ] - b[ 8 ];
            break;
        case 2:
            *str    = "BCG";
            return sum - b[ 0 ] - b[ 5 ] - b[ 7 ];
            break;
        case 3:
            *str    = "GBC";
            return sum - b[ 1 ] - b[ 3 ] - b[ 8 ];
            break;
        case 4:
            *str    = "GCB";
            return sum - b[ 1 ] - b[ 5 ] - b[ 5 ];
            break;
        case 5:
            *str    = "CBG";
            return sum - b[ 2 ] - b[ 3 ] - b[ 7 ];
            break;
        case 6:
            *str    = "CGB";
            return sum - b[ 2 ] - b[ 4 ] - b[ 6 ];
            break;
    }
}

int main()
{
    int b[ 9 ];

    while( cin >> b[0] >> b[1] >> b[2] >> b[3] >> b[4] >> b[5] >> b[6] >> b[7] >> b[8] )
    {
        int move    = b[0] + b[1] + b[2] + b[3] + b[4] + b[5] + b[6] + b[7] + b[8];

        int     small   = -1;
        string  str;

        for( int i = 1; i <= 6; ++i )
        {
            int s;
            string  s2;
            s   = take( i, &s2, b, move );

            if( s < small || small == -1 )
            {
                small   = s;
                str     = s2;
            }
            else if( s == small && s2 < str )
            {
                str = s2;
            }
        }

        cout    << str << " " << small << endl;
    }

    return 0;
}
klam
New poster
Posts: 5
Joined: Thu May 18, 2006 1:18 am

Post by klam »

since u've solve it can you actually help me with something? im running your test case, did you submit your program in the format:

input
input
output
output

or

input
output
input
output

i think mine is right but im getting WA
if you submited as the 1st one, does it end with a "end of line"?


EDITED: nvm, i found out how it works now.
klam
New poster
Posts: 5
Joined: Thu May 18, 2006 1:18 am

Re: Problem is solved!

Post by klam »

jan-jun-john wrote:I can get AC!!!

Code: Select all

while (true) {
if (cin.eof()) break;
.
.
.
This is the cause of WA.
This should be changed,

Code: Select all

while (scanf("%d %d %d %d %d %d %d %d %d", 
			&data[0],&data[1],&data[2], 
			&data[3],&data[4],&data[5], 
			&data[6],&data[7],&data[8])==9) {...
so according to this.... the process goes:

input
output
input
output
input
output

am i right?
is there an end of line at the end? must be unless u bother to check where's the last line and output without endl/println
himanshu
New poster
Posts: 17
Joined: Mon May 15, 2006 12:24 pm
Location: Hyderabad, India
Contact:

102 WA

Post by himanshu »

Hi XOPHT

I tried your code. It works fine on sample input. Could you figure out the problem. I think it is quite well written.

Himanshu
ayeshapakhi
Learning poster
Posts: 60
Joined: Sun Apr 16, 2006 7:59 pm

102 WA pls tell me where is the problem??????

Post by ayeshapakhi »

here's the code...........

Thanks for any help.

the code is removed after getting AC

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

Code: Select all




for(i=0; i<N; i++)
		{			if(allcomb[i]<min)
			{
				strcpy(glass,col[i]);
				min=allcomb[i];			
			}
			else if(allcomb[i]==min)
			{
				if( strcmp(glass,col[i])==1) 
					strcpy(glass,col[i]);
			}
		}
		printf("%s %ld\n",glass,min);

Last edited by ayeshapakhi on Wed May 31, 2006 7:08 am, edited 1 time in total.
tan_Yui
Experienced poster
Posts: 155
Joined: Sat Jul 10, 2004 12:41 am

Re: 102 WA pls tell me where is the problem??????

Post by tan_Yui »

Hi, ayeshapakhi.
I think the cause of WA is your strcmp usage.

Please change to
strcmp(glass,col)>0

Best regards.
ayeshapakhi
Learning poster
Posts: 60
Joined: Sun Apr 16, 2006 7:59 pm

Post by ayeshapakhi »

dear tan_Yui...
Thanks a tonnn for ur help.......
i got accepted at last!!!!! :D
i missed that point......
thanks again..
:D
sathyashrayan
New poster
Posts: 6
Joined: Tue Apr 25, 2006 6:48 pm

Prob 102: help a beginner

Post by sathyashrayan »

Dear group,
I am beginner and I will be happy if some body
define the term "minimize the number of bottles that are moved".

I get different answer when the arrangement of the bin is subtracted
with the total number of bottle taking all the 3 into account. Is that
what they mean by movement of bottles. Pls help. thanks
sathyashrayan
New poster
Posts: 6
Joined: Tue Apr 25, 2006 6:48 pm

Post by sathyashrayan »

Are the new commers not allowed? :(
Post Reply

Return to “Volume 1 (100-199)”