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

Post Reply
hello world
New poster
Posts: 4
Joined: Fri Aug 02, 2002 6:04 pm

help,help,help:about data input of 102

Post by hello world » Sat Aug 03, 2002 7:50 am

1> when i use c++ :
[cpp] while(!cin.eof()){for(i=0;i<8;i++) cin>>n;}[/cpp]
i got wa;
2>when i use c++:
[cpp] while(cin>>n[0]>>n[1]......>>n[8]){};[/cpp]
i pass;
3>when i use c:
[c]while (!feof(stdin)){};[/c]
i pass;
why? can somebody tell me?

1_UtterBlue
New poster
Posts: 12
Joined: Sun Mar 10, 2002 2:00 am
Location: China
Contact:

Just a simply edit!

Post by 1_UtterBlue » Wed Aug 07, 2002 5:18 pm

You may have misunderstanding its output regular. It requires one to output the alphabetically first string representing a minimal configuration should be printed. You may have miss that! Try again! Good luck! :D
James.Hao (Bonjour!)

knight823
New poster
Posts: 3
Joined: Thu Aug 15, 2002 11:18 am

Help 102!!

Post by knight823 » Thu Aug 15, 2002 11:23 am

:cry:
please~~~~anyone can tell me!!
what's wrong!!

#include <iostream>
using namespace std;

void main()
{
do
{
int b[3][3],t[6];
int a=0,i,j,min;
for(i=0;i<=2;i++)
for(j=0;j<=2;j++)
cin>>b[j];
t[0]=b[1][1]+b[2][1]+b[0][2]+b[2][2]+b[0][0]+b[1][0];
t[1]=b[1][1]+b[2][1]+b[0][0]+b[2][0]+b[0][2]+b[1][2];
t[2]=b[1][2]+b[2][2]+b[0][1]+b[2][1]+b[0][0]+b[1][0];
t[3]=b[1][2]+b[2][2]+b[0][0]+b[2][0]+b[0][1]+b[1][1];
t[4]=b[1][0]+b[2][0]+b[0][1]+b[2][1]+b[0][2]+b[1][2];
t[5]=b[1][0]+b[2][0]+b[0][2]+b[2][2]+b[0][1]+b[1][1];
min=t[0];
for(i=1;i<=5;i++)
{
if(min>=t){min=t;a=i;}
}
switch(a)
{
case 0:cout<<"GCB";break;
case 1:cout<<"GBC";break;
case 2:cout<<"CGB";break;
case 3:cout<<"CBG";break;
case 4:cout<<"BGC";break;
case 5:cout<<"BCG";break;
}
cout<<" "<<min;
}
while(cin!=0);
}

Sisco Bermejo
New poster
Posts: 1
Joined: Fri Aug 16, 2002 4:58 am
Location: Pallars Juss

Post by Sisco Bermejo » Fri Aug 16, 2002 5:01 am

quoted from problem description:

"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. "

Good luck

dserrano
New poster
Posts: 7
Joined: Tue Sep 17, 2002 2:39 am

prob 102. Is there any trick on input data?

Post by dserrano » Tue Sep 17, 2002 2:46 am

I

zerocool
New poster
Posts: 7
Joined: Wed May 15, 2002 10:30 am
Location: Kaohsiung,Taiwan
Contact:

Post by zerocool » Wed Sep 18, 2002 8:56 am

In this problem, the reason why I get WA is "output format".
For example, When we output
123456789
It's may be transformed.
1.2E8
( The answer may be not correct. Just for example )
Unluckily, the output should be 123456789, so, do you get what I mean ?
:wink:
Best Regards
A mediocrityboy

dserrano
New poster
Posts: 7
Joined: Tue Sep 17, 2002 2:39 am

Post by dserrano » Wed Sep 18, 2002 9:57 pm

Can it happen with long integers?
I

ee
New poster
Posts: 1
Joined: Sun Sep 22, 2002 4:18 am

Why WA 102 SOS!

Post by ee » Sun Sep 22, 2002 4:20 am

/*@JUDGE_ID: 23416EM 102 C++ ""*/
@BEGIN_OF_SOURCE_CODE
#include<stdio.h>
#include<stdlib.h>
void main()
{
long a[10];
long b[4],g[4],c[4];
long aa,bb,cc;
long dd,ee;
int k;
int q[50];
long total[7];
long aaa,bbb,ccc,ddd,eee,fff;
int digit=-1;
int i;
while(1){

for(i=1;i<50;i++)
q=-1;

i=49;

k=scanf("%d%d%d%d%d%d%d%d%d",&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9]);
if(k!=9) break;
b[1]=a[1];b[2]=a[4];b[3]=a[7];
g[1]=a[2];g[2]=a[5];g[3]=a[8];
c[1]=a[3];c[2]=a[6];c[3]=a[9];
aaa=total[1]=b[2]+b[3]+c[1]+c[3]+g[1]+g[2];
bbb=total[2]=b[2]+b[3]+c[1]+c[2]+g[1]+g[3];
ccc=total[3]=b[1]+b[3]+c[2]+c[3]+g[1]+g[2];
ddd=total[4]=b[2]+b[1]+c[2]+c[3]+g[1]+g[3];
eee=total[5]=b[1]+b[3]+c[1]+c[2]+g[3]+g[2];
fff=total[6]=b[2]+b[1]+c[1]+c[3]+g[3]+g[2];

aa=(total[1]<total[2])?total[1]:total[2];
bb=(total[3]<total[4])?total[3]:total[4];
cc=(total[5]<total[6])?total[5]:total[6];

dd=(aa<bb)?aa:bb;
ee=(dd<total[6])?dd:total[6];
while(1){
if(ee==aaa){printf("BCG ");break;}
if(ee==bbb){printf("BGC ");break;}
if(ee==ccc){printf("CBG ");break;}
if(ee==ddd){printf("CGB ");break;}
if(ee==eee){printf("GBC ");break;}
if(ee==fff){printf("GCB ");break;}}

do{
digit=ee-ee/10*10;
ee=ee/10;
q=digit;
i--;
}while(ee>=1);
for(i=1;i<50;i++)
{
if(q==-1)continue;
printf("%d",q);
}
}
}
@END_OF_SOURCE_CODE

21743NX
New poster
Posts: 9
Joined: Tue Aug 27, 2002 8:39 am

Hi

Post by 21743NX » Wed Sep 25, 2002 8:07 am

There seemed to be nothing wrong with your program

I tested it and run it on my computer with my AC program.

the only problem maybe that you didn't print a endline after each ouput.

The online judge may see the ouput as

BCG 30CBG 50

instead of the desired
BCG 30
CBG 50

This is just my hunch, i don't have a 100% confidence that placing a endline will work but it does eliminate one of the possibility that it may not work which will scale down your effort looking for a bug.

give it a try!!1

7825JN
New poster
Posts: 1
Joined: Mon Sep 30, 2002 12:24 pm

102: Extreme MEMORY usage... WHY?? =))

Post by 7825JN » Mon Sep 30, 2002 12:27 pm

This is the source for my solution to 102: it works, but with approx. 388 kb of memory spent. Why I cannot understand! Doesn't malloc anything, and no recursion... must be something tricky. Do you know what it can be??

/Lars

SOURCE:

#include <stdio.h>
#define MAP(x) ((x==1)? 2 : (x==2)? 1 : 0)
int main(void)
{
int bins[3][3];
int i, j, k;
do
{
unsigned int best = 0xFF;
int min = 0;

for(i = 0; i < 9; i++)
{
scanf("%d", &((int*)bins));
min += ((int*)bins);
}

for(i = 0; i < 3; i++)
for(j = 0; j < 3; j++)
for(k = 0; k < 3; k++)
{
int sum = 0;
int n;

if(i == j || i == k || j == k)
continue;

for(n = 0; n < 9; n++)
{
int nn = n%3;
switch(n/3)
{
case 0:
if(nn != MAP(i))
sum += bins[0][nn];
break;
case 1:
if(nn != MAP(j))
sum += bins[1][nn];
break;
case 2:
if(nn != MAP(k))
sum += bins[2][nn];
break;
}
}

if(sum <= min)
{
/* check if "more" alphabetical... */
int test = k + (j << 2) + (i << 4);
/* best == 112233 */
if((test < best && sum == min) || best == 0xFF || sum < min)
best = test;
min = sum;
}
}

for(i = 4; i >= 0; i -= 2)
{
switch((best & (3 << i)) >> i)
{
case 0:
printf("B");
break;
case 1:
printf("C");
break;
case 2:
printf("G");
break;
}
}
printf(" %d\n", min);
scanf("\n");
}while(!feof(stdin));
return 0;
}

Ivor
Experienced poster
Posts: 150
Joined: Wed Dec 26, 2001 2:00 am
Location: Tallinn, Estonia

Post by Ivor » Mon Sep 30, 2002 2:08 pm

It's not the first time this question is asked, but once again -- it has something to do with internal IO buffering, I guess.

Ivor
There is a theory which states that if ever anyone discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.

supermin
New poster
Posts: 37
Joined: Sat Oct 12, 2002 9:54 am
Location: (Taiwan)
Contact:

102=>WA...help

Post by supermin » Sat Oct 12, 2002 10:02 am

I test it many times,but I still can't figure out why judge sends me WA....
Could anyone give me help..or ....just a sample input to show my wrong..
thanx..^^

[color=olive]#include<stdio.h>
int main(void)
{
long int can[3][3],BGC,BCG,GBC,GCB,CBG,CGB;
long int min_step;

while(scanf("%ld%ld%ld%ld%ld%ld%ld%ld%ld",&can[0][0],&can[0][1],&can[0][2],&can[1][0],&can[1][1],&can[1][2],&can[2][0],&can[2][1],&can[2][2])==9)
{
min_step=10000000;
BGC=BCG=GBC=GCB=CBG=CGB=0;
/* B G C
can1 can[0][0] can[0][1] can[0][2]
can2 can[1][0] can[1][1] can[1][2]
can3 can[2][0] can[2][1] can[2][2] */
BGC=can[0][1]+can[0][2]+can[1][0]+can[1][2]+can[2][0]+can[2][1];
BCG=can[0][1]+can[0][2]+can[1][0]+can[1][1]+can[2][0]+can[2][2];
GBC=can[0][0]+can[0][2]+can[1][1]+can[1][2]+can[2][0]+can[2][1];
GCB=can[0][0]+can[0][2]+can[1][0]+can[1][1]+can[2][1]+can[2][2];
CBG=can[0][0]+can[0][1]+can[1][1]+can[1][2]+can[2][0]+can[2][2];
CGB=can[0][0]+can[0][1]+can[1][0]+can[1][2]+can[2][1]+can[2][2];

/* printf("%ld %ld %ld %ld %ld %ld",BGC,BCG,GBC,GCB,CBG,CGB); */

if(min_step>BCG)
min_step=BCG;
if(min_step>BGC)
min_step=BGC;
if(min_step>CBG)
min_step=CBG;
if(min_step>CGB)
min_step=CGB;
if(min_step>GBC)
min_step=GBC;
if(min_step>GCB)
min_step=GCB;


if(min_step==BCG)
{
printf("BCG");
goto A;
}
if(min_step==BGC)
{
printf("BGC");
goto A;
}
if(min_step==CBG)
{
printf("CBG");
goto A;
}
if(min_step==CGB)
{
printf("CGB");
goto A;
}
if(min_step==GBC)
{
printf("GBC");
goto A;
}
if(min_step==GCB)
{
printf("GCB");
goto A;
}

A:
printf(" %ld\n",min_step);


}
return 0;
}[/color][/c]

User avatar
Ghost77 dimen
Learning poster
Posts: 67
Joined: Sun Sep 22, 2002 5:40 am
Location: Taiwan

Post by Ghost77 dimen » Sat Oct 19, 2002 3:11 am

8) Hi 8)
It will be helpful by replacing "long int" to int and "%ld" to "%d".
I am not firmly sure of that , but you can make it a try.

supermin
New poster
Posts: 37
Joined: Sat Oct 12, 2002 9:54 am
Location: (Taiwan)
Contact:

Post by supermin » Sat Oct 19, 2002 12:01 pm

hmm...I try it as you say..,but it still can't send me AC message..
Anyway,thanks..

Could anyone help me solve this problem..

junjieliang
Experienced poster
Posts: 169
Joined: Wed Oct 31, 2001 2:00 am
Location: Singapore

Post by junjieliang » Sat Oct 19, 2002 5:12 pm

I'm not sure, but perhaps you can initialise min_step to something bigger like 2147483647?

Post Reply

Return to “Volume 1 (100-199)”