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

=viki=
New poster
Posts: 23
Joined: Mon Jan 02, 2006 6:23 pm
Contact:

Post by =viki= »

damn... thats silly


thanx anyway for pointing out my error..
but how is it getting compile error though..
its doing fine on my system(using DEV C++)
Mohammad Mahmudur Rahman
Experienced poster
Posts: 154
Joined: Sat Apr 17, 2004 9:34 am
Location: EEE, BUET

Post by Mohammad Mahmudur Rahman »

In order to be compilled under judge your program must exclude all non-ANSI standard features. So, you can't use all your DEV-C++ compiler features & be assured that it'll be alright in the judge. You may consult your compiler's documentation for information about which features are ANSI standard & which are not.

to chunyi81:
Are you sure that a difference in %d & %ld will result in CE in UVa judge? :o I really doubt that. I think =viki= received CE in this program for using C++ style comment & submitting as C program. If this program is submitted as a C++ program, I don't think it'll get CE.
You should never take more than you give in the circle of life.
=viki=
New poster
Posts: 23
Joined: Mon Jan 02, 2006 6:23 pm
Contact:

Post by =viki= »

C++ style comment was the prob...

thanx for the help... i got AC after remo ving those comments...
=viki=
New poster
Posts: 23
Joined: Mon Jan 02, 2006 6:23 pm
Contact:

Post by =viki= »

got AC.... C++ style comment was the prob

after removing the comment i got AC....
chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

Post by chunyi81 »

Thanks to Mohammad Mahmudur Rahman for pointing out the actual problem. I was able to compile viki's code in a Unix environment using gcc 2.95.3 though, without any problems. And I realized why my code for problem 142 was getting CE from the judge when I submitted it as C code. I was also using C++ style comments myself in C code. :oops:

Is the OJ using an older version of the gcc 2.95 compiler?
totobogy
New poster
Posts: 7
Joined: Wed Jan 11, 2006 10:08 pm
Location: India
Contact:

102 - WA

Post by totobogy »

Hi! I'm new to ACM and this forum. plz help me with this. runs fine for sample input but gives WA on judge
aren't there only these six possibilities? can someone provide some test cases

Code: Select all

#include<stdio.h>

int main()
{
	unsigned long bins[9]; /*2d array[3][3] could hv been used too*/
	unsigned long cost[6];/*cost of BCG BGC CBG CGB GBC GCB (in that order) - only these six r possible*/
	unsigned long sum;
	
	int i;
	int c;
	while((c=getc(stdin)) != EOF)
	{
		ungetc(c,stdin);
		
		sum = 0; /*reset*/
		
  		/*BGC BGC BGC = 012 345 678*/
		for(i=0;i<9;i++)
		{
			scanf("%lu",&bins[i]);
			sum += bins[i];
		}
	
 		/*Now calculating costs*/
 		/*BCG*/
 		cost[0] = sum - (bins[0]+ bins[5]+ bins[7]);
 		/*BGC*/
 		cost[1] = sum - (bins[0]+ bins[4]+ bins[8]);
 		/*CBG*/
 		cost[2] = sum - (bins[2]+ bins[3]+ bins[7]);
 		/*CGB*/
 		cost[3] = sum - (bins[2]+ bins[4]+ bins[6]);
 		/*GBC*/
 		cost[4] = sum - (bins[1]+ bins[3]+ bins[8]);
 		/*GCB*/
 		cost[5] = sum - (bins[1]+ bins[5]+ bins[6]);
	
        /*find smallest cost packing scheme*/
	
         int min = 0;
         for(i=1;i<6;i++)
         	if(cost[i] < cost[min])
         		min = i;
			
	    /*print output*/
	    switch(min)
	    {
	    	case 0: printf("BCG %lu\n",cost[min]);break;
	    	case 1: printf("BGC %lu\n",cost[min]);break;
	    	case 2: printf("CBG %lu\n",cost[min]);break;
	    	case 3: printf("CGB %lu\n",cost[min]);break;
	    	case 4: printf("GBC %lu\n",cost[min]);break;
	    	case 5: printf("GCB %lu\n",cost[min]);break;
    	}
	}
	return 0;
}


Mohammad Mahmudur Rahman
Experienced poster
Posts: 154
Joined: Sat Apr 17, 2004 9:34 am
Location: EEE, BUET

Post by Mohammad Mahmudur Rahman »

Try taking the input in this way -

Code: Select all

while(scanf(" %lu",&bins[0])==1)
{ 
      sum = bins[0]; /*reset*/ 
       
        /*BGC BGC BGC = 012 345 678*/ 
      for(i=1;i<9;i++) 
      { 
         scanf("%lu",&bins[i]); 
         sum += bins[i]; 
      }
    
      .....
}
Everything else should be OK.
You should never take more than you give in the circle of life.
totobogy
New poster
Posts: 7
Joined: Wed Jan 11, 2006 10:08 pm
Location: India
Contact:

Thanks. It worked

Post by totobogy »

Thanks a lot. This was the problem indeed. But could you tell me why didn't the earlier code work?
Mohammad Mahmudur Rahman
Experienced poster
Posts: 154
Joined: Sat Apr 17, 2004 9:34 am
Location: EEE, BUET

Post by Mohammad Mahmudur Rahman »

As far as my experience goes, ungetc() method at times (not always) fails in the UVa judge. The reason is most probably, there may be some spaces after an input line. For example, test your program for the following input

Code: Select all

1_2_3_4_5_6_7_8_9
1_2_3_4_5_6_7_8_9_
/* Here each underscore represents a single space char. */
if you use getc() & ungetc(), I think you'll get

Code: Select all

BCG 30
BCG 30
BCG 30
You should never take more than you give in the circle of life.
totobogy
New poster
Posts: 7
Joined: Wed Jan 11, 2006 10:08 pm
Location: India
Contact:

Thanks again

Post by totobogy »

I see. Thanks for the valuable clarification and your time!
jan-jun-john
New poster
Posts: 6
Joined: Tue Feb 07, 2006 6:26 pm
Location: Japan

102 please help!

Post by jan-jun-john »

I can't get "Accepted", but I don't know what is wrong with my program.
Please, help!

Code: Select all

Sorry, it was removed.
Last edited by jan-jun-john on Thu Feb 09, 2006 5:02 pm, edited 1 time in total.
jan-jun-john
New poster
Posts: 6
Joined: Tue Feb 07, 2006 6:26 pm
Location: Japan

Post by jan-jun-john »

I noticed these sentences not filled well.
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.
So, I improved my code, but still WA...
Where is Wrong ?

Code: Select all

Sorry, it was removed.
Last edited by jan-jun-john on Thu Feb 09, 2006 5:02 pm, edited 1 time in total.
jan-jun-john
New poster
Posts: 6
Joined: Tue Feb 07, 2006 6:26 pm
Location: Japan

Problem is solved!

Post by jan-jun-john »

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) {...
I hope my effort will help following person!
chiunyao
New poster
Posts: 4
Joined: Mon Feb 13, 2006 11:07 am

102 help me always "Compile error"

Post by chiunyao »

I always get Compile error ,but i don't know why??

please help me ,i'm new to ACM ><



thanks

Code: Select all

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


	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(int k=0;k<6;k++) 
	{ 

		if(b[k]<MIN) 
		{ 
			MIN=b[k]; 
			MINNUM=k; 
		} 
	} 
		if(MINNUM==0) 
		printf("BCG %lu\n",b[0]);
	else if(MINNUM==1)
		printf("BGC %lu\n",b[1]);
	else if(MINNUM==2) 
		printf("CBG %lu\n",b[2]);
	else if(MINNUM==3)
		printf("CGB %lu\n",b[3]);
	else if(MINNUM==4)
		printf("GBC %lu\n",b[4]);
	else if (MINNUM==5)
		printf("GCB %lu\n",b[5]);
	 	} 
return 0; 
} 
shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

Post by shamim »

I submitted your code as C++ and it did not get compile error.
But it got compile error using the C option.
Perhaps this is the problem. :wink:
Post Reply

Return to “Volume 1 (100-199)”