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

globi
New poster
Posts: 15
Joined: Wed Apr 23, 2003 2:44 pm
Location: Warsaw
Contact:

102 - Compile Error

Post by globi »

Hello. I wrote program nr. 102 but I received Compile Error
Could anyone help me?
There's a source code:

[cpp]
#include <stdio.h>

#define B 0 // Brown bottles
#define G 1 // Green bottles
#define C 2 // Clear bottles

int main()
{
char *done;
int pass;
long long bins[3][3],
oldbins,
count,
max;

while(1)
{
pass = 0;
max = 0xffffffffff;
count = 0;

for(int tmp = 0; tmp < 3; tmp++)
for(int tmp2 = 0; tmp2 < 3; tmp2++)
{
oldbins = bins[tmp][tmp2];
scanf("%lld", &bins[tmp][tmp2]);
if(oldbins == bins[tmp][tmp2]) pass++;
}

if(pass == 9) return 0;

count = bins[0][C]+bins[0]+bins[1][G]+bins[1]+bins[2][G]+bins[2][C];
if(count <= max) { max = count; done = "GCB";}
count = bins[0]+bins[0][C]+bins[1][G]+bins[1][C]+bins[2][G]+bins[2];
if(count <= max) { max = count; done = "GBC";}
count = bins[0][G]+bins[0]+bins[1][C]+bins[1]+bins[2][C]+bins[2][G];
if(count <= max) { max = count; done = "CGB";}
count = bins[0]+bins[0][G]+bins[1][C]+bins[1][G]+bins[2][C]+bins[2];
if(count <= max) { max = count; done = "CBG";}
count = bins[0][G]+bins[0][C]+bins[1]+bins[1][C]+bins[2]+bins[2][G];
if(count <= max) { max = count; done = "BGC";}
count = bins[0][C]+bins[0][G]+bins[1][B]+bins[1][G]+bins[2][B]+bins[2][C];
if(count <= max) { max = count; done = "BCG";}

printf("%s %lld\n", done, max);

}
return 0;
}
[/cpp]

turuthok
Experienced poster
Posts: 193
Joined: Thu Sep 19, 2002 6:39 am
Location: Indonesia
Contact:

Post by turuthok »

Did you submit as C or C++ ... ??? If you're using C, ... "//" will cause an error ...

-turuthok-
The fear of the LORD is the beginning of knowledge (Proverbs 1:7).

venusaur
New poster
Posts: 4
Joined: Wed Apr 23, 2003 3:05 pm

My answer of #102 received [WA]

Post by venusaur »

[java]import java.io.*;
import java.util.*;

class Main
{
public static String readln(int len)
{
byte lin[]=new byte[len];
int lg=0, car=-1;
try
{
while(lg<len)
{
car=System.in.read();
// if(lg==0&&(car=='\r')||(car=='\n')) continue;
// if((car<0)||(car=='\r')||(car=='\n')) break;
if((car<0)||(car=='\n')) break;
lin[lg++]+=car;
}
}
catch (IOException e) { return null; }
if((car<0)&&(lg==0)) return null;
return new String(lin, 0, lg);
}

static int permute[][]={{0, 2, 1}, {0, 1, 2}, {2, 0, 1}, {2, 1, 0}, {1, 0, 2}, {1, 2, 0}};
static String perstr[]={"BCG", "BGC", "CBG", "CGB", "GBC", "GCB"};

static int compute(int bin[][], int p)
{
int ret=0;
for(int i=0;i<3;i++) for(int j=0;j<3;j++) if(permute[p]!=j) ret+=bin[j];
return ret;
}

public static void main (String args[])
{
String str;
while((str=readln(80))!=null)
{
StringTokenizer token=new StringTokenizer(str);
String minstr; int minnum;
int bin[][]=new int[3][3];
for(int i=0;i<3;i++) for(int j=0;j<3;j++) bin[j]=Integer.parseInt(token.nextToken());
minstr=perstr[0]; minnum=compute(bin, 0);
for(int i=1;i<6;i++)
{
int t=compute(bin, i);
if(t<minnum) { minstr=perstr; minnum=t; }
}
System.out.println(minstr+" "+minnum);
}
}
}[/java]
I think I have some mistakes but I can't find it
Please help me... :(

globi
New poster
Posts: 15
Joined: Wed Apr 23, 2003 2:44 pm
Location: Warsaw
Contact:

Post by globi »

I sent it as cpp code, so it should work.

globi
New poster
Posts: 15
Joined: Wed Apr 23, 2003 2:44 pm
Location: Warsaw
Contact:

Post by globi »

It's working now. There was an error in line

[cpp]
max = 0xffffffffff;
[/cpp]

There was too small :)

Thx everyone.

globi
New poster
Posts: 15
Joined: Wed Apr 23, 2003 2:44 pm
Location: Warsaw
Contact:

Post by globi »

Ok :)

I repaired that and I accepted.

Thx.

Zhao Le
Learning poster
Posts: 80
Joined: Mon May 05, 2003 4:09 am
Location: Shanghai,China

102 Why WA?

Post by Zhao Le »

Here is my code.
I don't understand why i got WA?
Who can help me i shall be grateful.

[cpp]#include <iostream.h>

struct S
{
int min,cnt;
S *next;
};

struct Glass
{
long Brown,Green,Clear;
};

long Calculate(Glass A,Glass B,Glass C)
{
return A.Green+A.Clear+B.Brown+B.Clear+C.Brown+C.Green;
}

int Convert(int x)
{
switch(x)
{
case 1: return 2;
case 2: return 1;
case 3: return 5;
case 4: return 3;
case 5: return 6;
default: return 4;
}
}


void SS(int i)
{
switch(i)
{
case 1: cout<<"BGC";break;
case 2: cout<<"BCG";break;
case 3: cout<<"GBC";break;
case 4: cout<<"CBG";break;
case 5: cout<<"GCB";break;
case 6: cout<<"CGB";
}
}

void main()
{
long B0,B1,B2,G0,G1,G2,C0,C1,C2;
Glass G[3];
S *p,*q,*head=NULL;
while(cin>>B0>>G0>>C0>>B1>>G1>>C1>>B2>>G2>>C2)
{
G[0].Brown=B0; G[1].Brown=B1; G[2].Brown=B2;
G[0].Green=G0; G[1].Green=G1; G[2].Green=G2;
G[0].Clear=C0; G[1].Clear=C1; G[2].Clear=C2;
int x=0,cnt=7,i,j,k;
long min=65535,t;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
for(k=0;k<3;k++)
if(i!=j&&i!=k&&j!=k) // cout<<i<<j<<k<<endl;
{
x++;
t=Calculate(G,G[j],G[k]);
if(min>=t)
{
if(min>t)
{
cnt=x;
min=t;
}
else
if(Convert(x)<Convert(cnt))
cnt=x;
}
}
}
p=new S;
if(head==NULL) head=p;
else q->next=p;
p->min=min;
p->cnt=cnt;
p->next=NULL;
q=p;
}
for(p=head;p;p=p->next)
{
SS(p->cnt);
cout<<" "<<p->min<<endl;
}
}[/cpp]

Master
Learning poster
Posts: 82
Joined: Thu Oct 10, 2002 1:15 pm
Location: St. Johns, Canada
Contact:

think it easy

Post by Master »

your code is learge but the problem is small :wink:

I solve this problem very simple way. there is only 6 type of combination.
check all of them.

use a two dimentional matrix for make it easy.

wish you good luck

Master
Learning poster
Posts: 82
Joined: Thu Oct 10, 2002 1:15 pm
Location: St. Johns, Canada
Contact:

think it easy

Post by Master »

your code is learge but the problem is small :wink:

I solve this problem very simple way. there is only 6 type of combination.
check all of them.

use a two dimentional matrix for make it easy.

wish you good luck

Zhao Le
Learning poster
Posts: 80
Joined: Mon May 05, 2003 4:09 am
Location: Shanghai,China

Post by Zhao Le »

Yes, but when the number is same,it should sort,right?
So i still don't know what the problem was?

Can you tell me?

epsilon0
Experienced poster
Posts: 112
Joined: Tue Nov 12, 2002 11:15 pm
Location: Paris, France.

Post by epsilon0 »

short analysis of your problem:

1] they wrote:

"The total number of bottles will never exceed 2^31."

2] you wrote:

"long min=65535,t;"

3] conclusion: cannot determine wether you can't read, can't do math, or both.

pardon my roughness, but this kind of error makes me mad. your code is nearly perfect, but it's plagged by a very stupid error.

regards.
We never perform a computation ourselves, we just hitch a ride on the great Computation that is going on already. --Tomasso Toffoli

Zhao Le
Learning poster
Posts: 80
Joined: Mon May 05, 2003 4:09 am
Location: Shanghai,China

thank you

Post by Zhao Le »

I have got it AC.

There are 2 errors.

One you have pointed to me, another is
that i should not use the pointer to save the result.

Thank you, I have often see you helped me and My friends in the Net.

reza ali
New poster
Posts: 6
Joined: Mon Jun 09, 2003 12:31 am

compiler error (102)

Post by reza ali »

Finding compiler error at problem 102.Please findout error :cry: . Here below the code:[c++}]


//@begin_of_source_code
#include<iostream.h>

int main()
{
/*@JUDGE_ID: 32434ZM 102 C++ "Dynamic programming" */
int i,j,bin[3][3],sum[3],min,take;
char *str[6][3],*sequence[3];
while (cin>>bin[0][0]>>bin[0][1]>>bin[0][2]>>bin[1][0]>>bin[1][1]>>bin[1][2]>>bin[2][0]>>bin[2][1]>>bin[2][2])
{
if(bin[1][1]+bin[2][2]<=bin[1][2]+bin[2][1]) {sum[0]=bin[0][1]+bin[0][2]+bin[1][0]+bin[2][0]+bin[1][1]+bin[2][2];*str[0]="BCG";}
else {sum[0]=bin[0][1]+bin[0][2]+bin[1][0]+bin[2][0]+bin[1][2]+bin[2][1];*str[0]="BGC";}
if(bin[0][1]+bin[2][2]<=bin[0][2]+bin[2][1]) {sum[1]=bin[0][0]+bin[2][0]+bin[1][1]+bin[1][2]+bin[0][1]+bin[2][2];*str[1]="CBG";}
else {sum[1]=bin[1][0]+bin[1][2]+bin[0][1]+bin[2][1]+bin[0][2]+bin[2][1];*str[1]="GBC";}
if(bin[0][1]+bin[1][2]<=bin[0][2]+bin[1][1]) {sum[2]=bin[1][0]+bin[0][0]+bin[2][1]+bin[2][2]+bin[0][1]+bin[1][2];*str[2]="CGB";}
else {sum[2]=bin[1][0]+bin[2][1]+bin[2][2]+bin[1][2]+bin[1][1]+bin[0][2];*str[2]="GCB";}

if(sum[0]<=sum[1]){
if(sum[0]<=sum[2]) {min=sum[0];*sequence=*str[0];}
else {min=sum[2];*sequence=*str[2];}
}
else {
if(sum[1]<=sum[2]) {min=sum[1];*sequence=*str[1];}
else {min=sum[2];*sequence=*str[2];}
}
cout<<*sequence<<" "<<min<<endl;}
return 0;
}
//@end_of_source_code[cpp][/cpp]

shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

Looks ok

Post by shamim »

ur code compiles using g++(cygwin).

I think the problem is in ur submission.

If u submit using email, some additional things are included,
worse still is, certain mail services transfer ur mail as graphics instead of plain text.

Let me know if this is the problem

Rav
New poster
Posts: 27
Joined: Sat Jun 14, 2003 1:00 pm
Location: Polska Wroc&#322;aw

Post by Rav »

Could someone tell what is wrong? I think that my compiler isn't good, but when i send it was error. This program is compiling good, but show wrong answer. it isn't entering two last IF-instructiona. I don't know why.
#include<stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>


int main()
{

long long int t[10];
long long int max,suma;
int i;
char nap[3];
#ifndef ONLINE_JUDGE
close (0); open ("myprog.in", O_RDONLY);
close (1); open ("myprog.out", O_WRONLY | O_CREAT, 0600);
#endif
t[9]=0;
while ((scanf("%d",&t[0]))==1)
{
for (i=1;i<9;++i)
scanf("%d",&t);
suma=0;
for (i=0;i<9;++i)
suma=suma+t;


max=t[1]+t[5]+t[6];
nap[0]='G';nap[1]='C';nap[2]='B';

if (t[1]+t[3]+t[8]>=max)
{
max=t[1]+t[3]+t[8];
nap[0]='G';nap[1]='B';nap[2]='C';
}

if (t[2]+t[5]+t[6]>=max)
{
max=t[2]+t[5]+t[6];
nap[0]='C';nap[1]='G';nap[2]='B';
}

if (t[2]+t[3]+t[7]>=max)
{
max=t[2]+t[3]+t[7];
nap[0]='C';nap[1]='B';nap[2]='G';
}

if (t[0]+t[4]+t[8]>=max) //this
{
max=t[0]+t[4]+t[8];
nap[0]='B'; nap[1]='G'; nap[2]='C';
}

if (t[0]+t[5]+t[7]>=max) //and this
{
max=t[0]+t[5]+t[7];
nap[0]='B'; nap[1]='C'; nap[2]='G';
}
printf("%c%c%c %d\n",nap[0],nap[1],nap[2],suma-max);
}
}

Post Reply

Return to “Volume 1 (100-199)”