Page 4 of 33

102 problem..

Posted: Mon May 20, 2002 8:36 am
by mindae
INPUT Data {1,2,3,4,5,6,7,8,9}; OUTPUT Data is GBC,GCB,BGC,BCG,CBG,CGBall correct .
Because 1,2,3.. is Arithmetic Sequence :oops:
Moreover Minimum size is constant also.

Tech me :(

T_T *3

Posted: Mon May 20, 2002 10:31 am
by mindae
Thx :0
but i got WA also.

INPUT
342343434 1000000000 234333333 21342134 12341234 12345345 3455555 5645656 5
234234 12341234 1234234 4563456 5674576 476476 45764576 45764576 23452345
21341234 12341234 12341234 234334 56456 4563456 34563456 78768 5685678
23423423 23 3 34234 234234 234234 234234 456456 78


OUTPUT

GBC 610464557
GCB 80923421
GCB 39737704
BCG 502806


i don't know that why i got WA.

Posted: Mon May 20, 2002 3:29 pm
by ithamar
You are right. GBC, GCB, BCG, ..., etc are correct but you have to read more carefuly the problem description because it says:

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



Hope it can help u.

bye

^-^

Posted: Mon May 20, 2002 3:37 pm
by mindae
Thx
i can't read english,well.
thank you
;)

"IN ALPHABETICAL ORDER"

Posted: Mon May 20, 2002 4:43 pm
by minskcity
ALL you numbers are correct,
but for "1 2 3 4 5 6 7 8 9" Input
YOU should print "BCG 30"

Ok

Posted: Mon May 20, 2002 6:31 pm
by mindae
BCG 30 ..
I repair my code . so minimum is select Foward alphabet.
But .. I recive WA from judge ,also
Probably i will crazy.. :(

check the printf portion of your code

Posted: Thu Jun 06, 2002 6:19 am
by ricky_bd
konsept wrote:Can someone please tell what is wrong with this problem, because I can't figure out why the online judge fails to accept it.

#include <stdio.h>
#include <string.h>

int box[4][4];

int bestcost;
char bestbin[16];

int check( int a,int b,int c ){
int cost=0;

cost+=box[1][1]+box[1][2]+box[1][3]-box[1][a];
cost+=box[2][1]+box[2][2]+box[2][3]-box[2];
cost+=box[3][1]+box[3][2]+box[3][3]-box[3][c];

return cost;
}

void main( void ){

while ( scanf( "%d %d %d", &box[1][1],&box[1][2],&box[1][3] )>0 ){
scanf( "%d %d %d", &box[2][1],&box[2][2],&box[2][3] );
scanf( "%d %d %d", &box[3][1],&box[3][2],&box[3][3] );

bestcost=1000000;

if ( check(1,3,2)<bestcost ){
bestcost=check(1,3,2);
strcpy( bestbin, "BCG" );
}

if ( check(1,2,3)<bestcost ){
bestcost=check(1,2,3);
strcpy( bestbin, "BGC" );
}

if ( check(3,1,2)<bestcost ){
bestcost=check(3,1,2);
strcpy( bestbin, "CBG" );
}

if ( check(3,2,1)<bestcost ){
bestcost=check(3,2,1);
strcpy( bestbin, "CGB" );
}


if ( check(2,1,3)<bestcost ){
bestcost=check(2,1,3);
strcpy( bestbin, "GBC" );
}

if ( check(2,3,1)<bestcost ){
bestcost=check(2,3,1);
strcpy( bestbin, "GCB" );
}

printf( "%s %dn", bestbin, bestcost );
}

}


Posted: Fri Jun 07, 2002 2:04 am
by Stefan Pochmann
Ah, now I found it. You chose to fully quote the post you reply to (why?) and write your comment in the subject line.

Btw, the printf is probably correct. I guess you think the backslash is missing, but it was probably removed by this board and is included in the original code.

102 problem

Posted: Fri Jun 28, 2002 2:08 pm
by giovane
I don't find the error with this algoritm...
Please, could anyone find it???
Thanks for help...

#include <stdio.h>
void main()
{
int i,min;
unsigned long int num[9],b[9],S[6];
while (scanf("%d %d %d %d %d %d %d %d %d",&num[0],&num[1],&num[2],&num[3],&num[4],&num[5],&num[6],&num[7],&num[8])==9)
{
b[0]=num[0]+num[3];
b[1]=num[0]+num[6];
b[2]=num[3]+num[6];
b[3]=num[1]+num[4];
b[4]=num[2]+num[7];
b[5]=num[4]+num[7];
b[6]=num[2]+num[5];
b[7]=num[2]+num[8];
b[8]=num[5]+num[8];
S[0]=b[2]+b[7]+b[3];
S[1]=b[2]+b[4]+b[6];
S[2]=b[8]+b[1]+b[3];
S[3]=b[8]+b[4]+b[0];
S[4]=b[5]+b[1]+b[6];
S[5]=b[5]+b[7]+b[0];
min=0;
for (i=0;i<6;i++)
if (S<S[min])
min=i;
switch (min)
{
case 0:
printf("BCG %d\n",S[0]);
break;
case 1:
printf("BGC %d\n",S[1]);
break;
case 2:
printf("CBG %d\n",S[2]);
break;
case 3:
printf("CGB %d\n",S[3]);
break;
case 4:
printf("GBC %d\n",S[4]);
break;
case 5:
printf("GCB %d\n",S[5]);
break;
}
}
}

:( [c][/c]

Posted: Fri Jun 28, 2002 7:10 pm
by 10153EN
Despite your declaration of *unsigned long int*, your input using "%d" will read the value as *int*, So there will be value overflow when the input is 2^31 = 2147483648.

Posted: Fri Jun 28, 2002 9:04 pm
by Picard
the real problem is b[4]=num[2]+num[7];

ps: remove your full ID code from the posted source

Thanks...

Posted: Sat Jun 29, 2002 9:26 pm
by giovane
:D Thanks for your help...
I don't understand why I don'f find the error...

help:102!

Posted: Fri Aug 02, 2002 6:08 pm
by hello world
can someone tell me where i make a mistake?i always get WA.why?
thanks
[cpp]#include<iostream.h>


int main()
{
unsigned long bin[3][3];
/*bin[0][0] is the number of brown bottles of the first bin.
the other are similar.
0->brown,1->green,2->clear;and bin[1]->the second bin*/

int i,j,flag;
unsigned long c[6];
while(!cin.eof())
{

for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>bin[j];
c[0]=bin[0][1]+bin[0][2]+bin[1][0]+bin[1][1]+bin[2][0]+bin[2][2];//BCG
c[1]=bin[0][1]+bin[0][2]+bin[1][0]+bin[1][2]+bin[2][0]+bin[2][1];//BGC
c[2]=bin[0][0]+bin[0][1]+bin[1][1]+bin[1][2]+bin[2][0]+bin[2][2];//CBG
c[3]=bin[0][1]+bin[0][0]+bin[1][0]+bin[1][2]+bin[2][1]+bin[2][2];//CGB
c[4]=bin[0][0]+bin[0][2]+bin[1][1]+bin[1][2]+bin[2][0]+bin[2][1];//GBC
c[5]=bin[0][0]+bin[0][2]+bin[1][0]+bin[1][1]+bin[2][1]+bin[2][2];//GCB
unsigned long min=c[0];
flag=0;
for(i=1;i<6;i++)
{
if(min>c)
{
min=c;
flag=i;
}
}
switch (flag)
{
case 0:cout<<"BCG ";break;
case 1:cout<<"BGC ";break;
case 2:cout<<"CBG ";break;
case 3:cout<<"CGB ";break;
case 4:cout<<"GBC ";break;
case 5:cout<<"GCB ";break;
}
cout<<c[flag]<<endl;
}
return 0;
}




[/cpp]

Posted: Fri Aug 02, 2002 6:27 pm
by vivid
May be not
bin[0][1]+bin[0][2]+bin[1][0]+bin[1][1]+bin[2][0]+bin[2][2]

but
bin[0][1]+bin[0][2]+bin[1][0]+bin[1][2]+bin[2][0]+bin[2][1] ?

Posted: Fri Aug 02, 2002 6:33 pm
by hello world
no.it should be the original code.