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

jc1987
New poster
Posts: 1
Joined: Fri Sep 22, 2006 7:19 pm

sorry I got 102 WA still....

Post by jc1987 » Fri Sep 22, 2006 7:25 pm

I've read previous articles about 102 WA and corrected some,
yet I still got WA and couldn't find anything I was able to help solve it...

Is that I didn't use string as output?

Appreciate for help, thanks!

Code: Select all

#include <iostream>

using namespace std;

int main(){
    
    unsigned long int bb[3], gg[3], cc[3];
    unsigned long int b[3], g[3], c[3];
    char bin[3];
    
    while(cin>>bb[0]>>gg[0]>>cc[0]>>bb[1]>>gg[1]>>cc[1]>>bb[2]>>gg[2]>>cc[2]){

    
    
    for(int i=0; i<3; i++){
            b[i]=bb[(i+1)%3]+bb[(i+2)%3];
            g[i]=gg[(i+1)%3]+gg[(i+2)%3];
            c[i]=cc[(i+1)%3]+cc[(i+2)%3];    
            }
    
    


    unsigned long int move=0, min=b[0]+g[1]+c[2];
    bin[0]='B';
    bin[1]='G';
    bin[2]='C';
    
                    
for(int i=0; i<3; i++){
     for(int jj=i+1; jj<i+3; jj++){
             
             
             int j=jj%3;
                       
 
               
               
               int k=3-i-j;
               move=b[i]+g[j]+c[k];

               
           if(!((i==0)&&(j==1)&&(k==2))){
                                       
               if(move<min){
                  
                  bin[i]='B';
                  bin[j]='G';
                  bin[k]='C';
                  
                  min=move;
                  }
                  
               else if(move==min){
                    if(bin[0]=='C'){ 

                        if(i==0){
                        bin[i]='B';
                        bin[j]='G';
                        bin[k]='C';    

                        }
                    }
                        
                    else if(bin[0]=='G'){
                        bin[i]='B';
                        bin[j]='G';
                        bin[k]='C';

                        }
                        
                    else if(bin[0]=='B'){

                         if(i==0){
                        bin[0]='B';
                        bin[1]='C';
                        bin[2]='G';

                    }
                    } 
               }                     
        }     
        

}
}

    cout<<bin[0]<<bin[1]<<bin[2]<<" "<< min<<endl;
    
}

    return 0;
}

User avatar
smilitude
Experienced poster
Posts: 137
Joined: Fri Jul 01, 2005 12:21 am

Post by smilitude » Mon Sep 25, 2006 11:27 pm

I had really bad time to solve this problem.
Plz read the other threads again, and then again check your code.
If there is no error, then recode the whole things...

I am really sorry for such a upsetting suggestion. But I really had very bad time with this one!
fahim
#include <smile.h>

jjacm
New poster
Posts: 1
Joined: Wed Nov 22, 2006 5:27 am

102 Time Limit Exceeded

Post by jjacm » Wed Nov 22, 2006 5:31 am

#include <iostream>
#include <sstream>
#include <string>
int main( )
{
std::string bins[6]={"BCG","BGC","CBG","CGB","GBC","GCB"};
int index_bins=0; // remember which way has min moves
unsigned long moves[6]; // remember steps of each ways to move
unsigned long in[9]; // stores intput each line
unsigned long min_moves; // the minimum steps to complete recycling
std::ostringstream out_msg; // messages to be printed out
while(std::cin>>in[0]>>in[1]>>in[2]>>in[3]>>in[4]>>in[5]>>in[6]>>in[7]>>in[8])
{
min_moves=2147483647; // minimum moves to pack
//calculate all steps of moves
moves[0]=in[1]+in[2]+in[3]+in[4]+in[6]+in[8];
if(moves[0]<min_moves)
{
min_moves=moves[0];
index_bins=0;
}
moves[1]=in[1]+in[2]+in[3]+in[5]+in[6]+in[7];
if(moves[1]<min_moves)
{
min_moves=moves[1];
index_bins=1;
}
moves[2]=in[0]+in[1]+in[4]+in[5]+in[6]+in[8];
if(moves[2]<min_moves)
{
min_moves=moves[2];
index_bins=2;
}
moves[3]=in[0]+in[1]+in[3]+in[5]+in[7]+in[8];
if(moves[3]<min_moves)
{
min_moves=moves[3];
index_bins=3;
}
moves[4]=in[0]+in[2]+in[4]+in[5]+in[6]+in[7];
if(moves[4]<min_moves)
{
min_moves=moves[4];
index_bins=4;
}
moves[5]=in[0]+in[2]+in[3]+in[4]+in[7]+in[8];
if(moves[5]<min_moves)
{
min_moves=moves[5];
index_bins=5;
}
out_msg<<bins[index_bins]<<" "<<min_moves<<std::endl;
}
std::cout<<out_msg.str();
}



//===============================================================

but this code works just fine on my pc
i just dont get how it exceeds 10 secs on a P-III
plaease correct me ,thx

blitzritz
New poster
Posts: 2
Joined: Sat Sep 23, 2006 9:44 pm

102 WA someone please help! (noob)

Post by blitzritz » Sun Jan 14, 2007 10:39 am

Hi, both of my codes arent working. the first one gives WA and the second one gives Runtime Error: 102. i dunno whats wrong :S
someone please help me out here.

here are the codes:-

Code: Select all

#include<stdio.h>

char *ch[6] = { "BGC", "GBC", "BCG", "CGB", "CBG", "GCB" };
unsigned int bin1[3], bin2[3], bin3[3], a[6], min;
int i, ind;

void main()
{
while(scanf("%u %u %u %u %u %u %u %u %u", &bin1[0], &bin1[1], &bin1[2], &bin2[0], &bin2[1], &bin2[2], &bin3[0], &bin3[1], &bin3[2]) != EOF)
{

a[0] =bin2[0]+bin3[0]+bin1[1]+bin3[1]+bin1[2]+bin2[2];
a[1] =bin2[1]+bin3[1]+bin1[0]+bin3[0]+bin1[2]+bin2[2];
a[2] =bin2[0]+bin3[0]+bin1[2]+bin3[2]+bin1[1]+bin2[1];
a[3] =bin2[2]+bin3[2]+bin1[1]+bin3[1]+bin1[0]+bin2[0];
a[4] =bin2[2]+bin3[2]+bin1[0]+bin3[0]+bin1[1]+bin2[1];
a[5] =bin2[1]+bin3[1]+bin1[2]+bin3[2]+bin1[0]+bin2[0];

min = a[0];

for( i=0; i<=5; i++)
 {
  if(min > a[i])
   {
       min = a[i];
       ind = i;
    }
 }
printf("%s %u\n",ch[ind], min);
}

}
this one gave WA

Code: Select all

#include<stdio.h>

char *ans[20], *ch[6] = { "BGC", "GBC", "BCG", "CGB", "CBG", "GCB" };
unsigned int bin1[3], bin2[3], bin3[3], a[6], minv[20], min;
int i,j = -1, ind,count=0;


void main()
{
while(scanf("%u %u %u %u %u %u %u %u %u", &bin1[0], &bin1[1], &bin1[2], &bin2[0], &bin2[1], &bin2[2], &bin3[0], &bin3[1], &bin3[2]) != EOF)
{

a[0] =bin2[0]+bin3[0]+bin1[1]+bin3[1]+bin1[2]+bin2[2];
a[1] =bin2[1]+bin3[1]+bin1[0]+bin3[0]+bin1[2]+bin2[2];
a[2] =bin2[0]+bin3[0]+bin1[2]+bin3[2]+bin1[1]+bin2[1];
a[3] =bin2[2]+bin3[2]+bin1[1]+bin3[1]+bin1[0]+bin2[0];
a[4] =bin2[2]+bin3[2]+bin1[0]+bin3[0]+bin1[1]+bin2[1];
a[5] =bin2[1]+bin3[1]+bin1[2]+bin3[2]+bin1[0]+bin2[0];

min = a[0];

for( i=0; i<=5; i++)
 {
  if(min > a[i])
   {
       min = a[i];
       ind = i;
    }
 }
ans[++j] = ch[ind];
minv[j] = min;
count++;

}
for(i =0; i<count; i++)
printf("%s %u\n",ans[i],minv[i]);

}
this one gave :-
Runtime Error: 102
Your program has died with signal 11 (SIGSEGV). Meaning:

Invalid memory reference

Before crash, it ran during 0.008 seconds

plz help :cry:
thnx in advance

mickowong
New poster
Posts: 2
Joined: Thu Feb 08, 2007 9:08 pm

102 wa??

Post by mickowong » Thu Feb 08, 2007 9:13 pm

I have read all the post on this forum and find no solution on my problem,please help to check why a WA result:
i have taken the alphabetical order problem and try changing the type from int to long, i got correct output for test cases posted in this forum.
I think I made some silly problem , but where did I make it?

#include <iostream>
using namespace std;
long sum(long a,long b, long c,long d[])
{
long total=0;
for(int i=1;i<10;i++)
{if((i!=a)&&(i!=b)&&(i!=c))
total=total+d;
}
return total;
}
int main()
{
long a[10];
long b[6];

for (int i=1;i<10;i++)
cin>>a;
b[0]=sum(1,6,8,a);
b[1]=sum(1,5,9,a);
b[2]=sum(3,4,8,a);
b[3]=sum(3,5,7,a);
b[4]=sum(2,4,9,a);
b[5]=sum(2,6,7,a);

long min=2147483647;
long ind=0;
for(int i=0;i<6;i++)
{
if (min>b)
{
min=b;
ind=i;
}
}
switch (ind)
{
case 0:cout<<"BCG "<<min<<endl;
break;
case 1:cout<<"BGC "<<min<<endl;
break;
case 2:cout<<"CBG "<<min<<endl;
break;
case 3:cout<<"CGB "<<min<<endl;
break;
case 4:cout<<"GBC "<<min<<endl;
break;
case 5:cout<<"GCB "<<min<<endl;
break;
}
return 0;
}


//thankyou very much if you can help
Last edited by mickowong on Fri Feb 09, 2007 2:55 am, edited 1 time in total.

tgoulart
New poster
Posts: 42
Joined: Sat Oct 21, 2006 8:37 am
Location: Alegrete, Brazil

Post by tgoulart » Thu Feb 08, 2007 9:59 pm

I didn't look at your logic, but you are not handling the multiple input correctly, you only read ONE sequence of numbers. Look at the sample input and you will see it.
Thiago Sonego Goulart - UFMG/Brazil

mickowong
New poster
Posts: 2
Joined: Thu Feb 08, 2007 9:08 pm

Post by mickowong » Fri Feb 09, 2007 2:57 am

you are right, I just handled one line of input in the above code...what a silly mistake..................

Change the code to while (cin>>a[1]......a[9])
(actually i tried "while (true)" before , but got unlimited output problem..)
then got AC
the problem is solved thank you.

tgoulart
New poster
Posts: 42
Joined: Sat Oct 21, 2006 8:37 am
Location: Alegrete, Brazil

Post by tgoulart » Fri Feb 09, 2007 4:23 am

I'm glad you did it, but please remove your code from the forum. :wink:
Thiago Sonego Goulart - UFMG/Brazil

deadhunter411
New poster
Posts: 8
Joined: Sat Mar 10, 2007 10:20 am

102 WA PLZ HELP

Post by deadhunter411 » Sun Mar 11, 2007 3:56 pm

here is my c-code
thx for help :) !!

#include<stdio.h>

int main()
{
unsigned long int input[9];
unsigned long int result[6];
unsigned long int min;
int i,min_num=0;


while(scanf("%lu %lu %lu %lu %lu %lu %lu %lu
%lu",&input[0],&input[1],&input[2],&input[3],&input[4],&input[5],&input[6],&input[7],&input[8])!=EOF)
{

result[0]=input[1]+input[2]+input[3]+input[4]+input[6]+input[8];
result[1]=input[1]+input[2]+input[3]+input[5]+input[6]+input[7];
result[2]=input[0]+input[1]+input[4]+input[5]+input[6]+input[8];
result[3]=input[0]+input[1]+input[3]+input[5]+input[7]+input[8];
result[4]=input[0]+input[2]+input[4]+input[5]+input[6]+input[7];
result[5]=input[0]+input[2]+input[3]+input[4]+input[7]+input[8];

min=result[0];

for(i=1;i<=5;i++)
{
if(min>result)
{
min=result;
min_num=i;
}
}

switch(min_num)
{
case 0:
printf("BCG %lu\n",min);
break;
case 1:
printf("BGC %lu\n",min);
break;
case 2:
printf("CBG %lu\n",min);
break;
case 3:
printf("CGB %lu\n",min);
break;
case 4:
printf("GBC %lu\n",min);
break;
case 5:
printf("GCB %lu\n",min);
break;
}
}

return 0;
}


Q.Qnick
New poster
Posts: 5
Joined: Tue Mar 13, 2007 12:58 pm

102 what's wrong with my code

Post by Q.Qnick » Tue Mar 13, 2007 1:06 pm

i have tried 2 input such as
1 2 3 4 5 6 7 8 9
and
5 10 5 20 10 5 10 20 10
,and it works.
so i don't kown why online-judge didn't accept

there is my code

#include<stdio.h>
#include<stdlib.h>
long int save=0,lo,i=9;j=0,totle=0,k=0,po,l,SAVE;
long int *a,*b,*c;
main(){
a=(int*)malloc(sizeof(int)*9);
b=(int*)malloc(sizeof(int)*9);
c=(int*)malloc(sizeof(int)*3);

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

totle=0;
for(j=0;j<9;j++){
b[j]=a[j];
totle=totle+a[j];
}

for(k=0;k<3;k++){
lo=-1;po=-1;
for(j=0,save=0;j<i;j++){
if(a[j]>save){
save=a[j];
lo=j%3;
po=j/3;
}
}
totle-=save;
for(j=0;j<i;j++){
if(j%3==lo || j/3==po)a[j]=0;
}
c[po]=lo;
}


if(c[0]>c[1] && b[0]-b[1]==b[3]-b[4]){
save=c[0];
c[1]=c[0];
c[1]=save;
}
else if(c[1]>c[2] && b[3]-b[4]==b[6]-b[7]){
save=c[1];
c[1]=c[2];
c[2]=save;
}
else if(c[0]>c[2] && b[0]-b[1]==b[6]-b[7]){
save=c[0];
c[0]=c[2];
c[2]=save;
}
for(j=0;j<3;j++){
if(c[j]==0)printf("B");
else if(c[j]==1)printf("C");
else if(c[j]==2)printf("G");
}
printf(" %d\n",totle);
}
free(a);free(b);free(c);
}

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Post by helloneo » Tue Mar 13, 2007 2:39 pm


Ahadoom
New poster
Posts: 4
Joined: Sun Apr 15, 2007 1:28 am

[102] Output limit excedeed

Post by Ahadoom » Sun Apr 15, 2007 1:30 am

Code: Select all

Removed.
Problem solved, program was not ending at End of file (see the post below)
I already tested several cases posted on this forum and all returned a correct answer. Is int representation enough for this problem?

TIA
Last edited by Ahadoom on Sun Apr 15, 2007 1:51 pm, edited 1 time in total.

User avatar
Spykaj
New poster
Posts: 47
Joined: Sun May 21, 2006 12:13 pm

Post by Spykaj » Sun Apr 15, 2007 1:07 pm

Code: Select all

while(scanf("%d %d %d %d %d %d %d %d %d", &input[0], &input[1], &input[2], &input[3], &input[4], &input[5], &input[6], &input[7], &input[8])!=EOF)

Ahadoom
New poster
Posts: 4
Joined: Sun Apr 15, 2007 1:28 am

Post by Ahadoom » Sun Apr 15, 2007 1:39 pm

Spykaj wrote:

Code: Select all

while(scanf("%d %d %d %d %d %d %d %d %d", &input[0], &input[1], &input[2], &input[3], &input[4], &input[5], &input[6], &input[7], &input[8])!=EOF)
Thanks i got accepted. I thougth i could use scanf just like std::cin.

Post Reply

Return to “Volume 1 (100-199)”