102 - Ecological Bin Packing
Moderator: Board moderators
-
- New poster
- Posts: 4
- Joined: Fri Aug 02, 2002 6:04 pm
help,help,help:about data input of 102
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?
[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?
-
- New poster
- Posts: 12
- Joined: Sun Mar 10, 2002 2:00 am
- Location: China
- Contact:
Just a simply edit!
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!
James.Hao (Bonjour!)
Help 102!!
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);
}
-
- New poster
- Posts: 1
- Joined: Fri Aug 16, 2002 4:58 am
- Location: Pallars Juss
Why WA 102 SOS!
/*@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
@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
Hi
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
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
102: Extreme MEMORY usage... WHY?? =))
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;
}
/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;
}
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
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.
102=>WA...help
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]
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]
-
- Learning poster
- Posts: 67
- Joined: Sun Sep 22, 2002 5:40 am
- Location: Taiwan
-
- Experienced poster
- Posts: 169
- Joined: Wed Oct 31, 2001 2:00 am
- Location: Singapore