102 - Ecological Bin Packing
Moderator: Board moderators
-
- Experienced poster
- Posts: 154
- Joined: Sat Apr 17, 2004 9:34 am
- Location: EEE, BUET
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?
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.
to chunyi81:
Are you sure that a difference in %d & %ld will result in CE in UVa judge?

You should never take more than you give in the circle of life.
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.
Is the OJ using an older version of the gcc 2.95 compiler?

Is the OJ using an older version of the gcc 2.95 compiler?
102 - WA
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
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;
}
-
- Experienced poster
- Posts: 154
- Joined: Sat Apr 17, 2004 9:34 am
- Location: EEE, BUET
Try taking the input in this way -
Everything else should be OK.
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];
}
.....
}
You should never take more than you give in the circle of life.
Thanks. It worked
Thanks a lot. This was the problem indeed. But could you tell me why didn't the earlier code work?
-
- Experienced poster
- Posts: 154
- Joined: Sat Apr 17, 2004 9:34 am
- Location: EEE, BUET
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
/* Here each underscore represents a single space char. */
if you use getc() & ungetc(), I think you'll get
Code: Select all
1_2_3_4_5_6_7_8_9
1_2_3_4_5_6_7_8_9_
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.
Thanks again
I see. Thanks for the valuable clarification and your time!
-
- New poster
- Posts: 6
- Joined: Tue Feb 07, 2006 6:26 pm
- Location: Japan
102 please help!
I can't get "Accepted", but I don't know what is wrong with my program.
Please, help!
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.
-
- New poster
- Posts: 6
- Joined: Tue Feb 07, 2006 6:26 pm
- Location: Japan
I noticed these sentences not filled well.
Where is Wrong ?
So, I improved my code, but still WA...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.
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.
-
- New poster
- Posts: 6
- Joined: Tue Feb 07, 2006 6:26 pm
- Location: Japan
Problem is solved!
I can get AC!!!
This is the cause of WA.
This should be changed,
I hope my effort will help following person!
Code: Select all
while (true) {
if (cin.eof()) break;
.
.
.
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) {...
102 help me always "Compile error"
I always get Compile error ,but i don't know why??
please help me ,i'm new to ACM ><
thanks
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;
}