Page 24 of 33

Re: 102 help me always "Compile error"

Posted: Tue Feb 14, 2006 10:13 am
by sumankar
chiunyao wrote:

Code: Select all

for(int k=0;k<6;k++) 
That is not supported by the C language version judge's gcc takes in. Put the

Code: Select all

int k;
part somewhere at the top where you declare your variables and see if it works or not.

Posted: Tue Feb 14, 2006 2:47 pm
by chiunyao
Thanks for you help me to find the error,i have'd correct my code,
but i submitted my answer also get "wrong answer",i don't why?

Please help me thanks :)

Code: Select all

#include <stdio.h> 
int main(void) 
{ 
	 long int a[9]; 
	 long int b[6]; 
	 long int MIN=2147483647;
	 int MINNUM; 
	 int k;

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


	b[1]=a[3]+a[6]+a[1]+a[7]+a[2]+a[5]; 
	b[0]=a[3]+a[6]+a[2]+a[8]+a[1]+a[4]; 
	b[4]=a[4]+a[7]+a[0]+a[6]+a[2]+a[5]; 
	b[5]=a[4]+a[7]+a[2]+a[8]+a[0]+a[3]; 
	b[2]=a[5]+a[8]+a[0]+a[6]+a[1]+a[4]; 
	b[3]=a[5]+a[8]+a[1]+a[7]+a[0]+a[3]; 


	for(k=0;k<6;k++) 
	{ 

		if(b[k]<MIN) 
		{ 
			MIN=b[k]; 
			MINNUM=k; 
		} 
	} 
		if(MINNUM==0) 
		printf("BCG %ld\n",b[0]);
	else if(MINNUM==1)
		printf("BGC %ld\n",b[1]);
	else if(MINNUM==2) 
		printf("CBG %ld\n",b[2]);
	else if(MINNUM==3)
		printf("CGB %ld\n",b[3]);
	else if(MINNUM==4)
		printf("GBC %ld\n",b[4]);
	else if (MINNUM==5)
		printf("GCB %ld\n",b[5]);
	 	} 
return 0; 
} 

Posted: Tue Feb 14, 2006 6:41 pm
by IRA
I add one line code and got AC.....

Code: Select all

#include <stdio.h> 
int main(void) 
{ 
    long int a[9]; 
    long int b[6]; 
    long int MIN=2147483647; 
    int MINNUM; 
    int k; 

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

	MIN=2147483647;/////////////////////////// Becareful to reset ///////////////
   b[1]=a[3]+a[6]+a[1]+a[7]+a[2]+a[5]; 
   b[0]=a[3]+a[6]+a[2]+a[8]+a[1]+a[4]; 
   b[4]=a[4]+a[7]+a[0]+a[6]+a[2]+a[5]; 
   b[5]=a[4]+a[7]+a[2]+a[8]+a[0]+a[3]; 
   b[2]=a[5]+a[8]+a[0]+a[6]+a[1]+a[4]; 
   b[3]=a[5]+a[8]+a[1]+a[7]+a[0]+a[3]; 


   for(k=0;k<6;k++) 
   { 

      if(b[k]<MIN) 
      { 
         MIN=b[k]; 
         MINNUM=k; 
      } 
   } 
      if(MINNUM==0) 
      printf("BCG %ld\n",b[0]); 
   else if(MINNUM==1) 
      printf("BGC %ld\n",b[1]); 
   else if(MINNUM==2) 
      printf("CBG %ld\n",b[2]); 
   else if(MINNUM==3) 
      printf("CGB %ld\n",b[3]); 
   else if(MINNUM==4) 
      printf("GBC %ld\n",b[4]); 
   else if (MINNUM==5) 
      printf("GCB %ld\n",b[5]); 
       } 
return 0; 
} 

sorry i don't know your program..

Posted: Fri Mar 03, 2006 8:40 am
by sds1100
sorry i don't know your program..
sorry.sorry.sorry.sorry.sorry.

Why don't i get Accepted in 102?

Posted: Sun Mar 26, 2006 8:29 am
by Rulojuka
I'm trying to solve the problem 102 and I am having a problem.

I think my program is right, giving the correct answer in a good time without too much memory but i just get WA.

Please someone help me, this is the input that im testing:

1 2 3 4 5 6 7 8 9
5 10 5 20 10 5 10 20 10
0 0 0 0 0 0 0 0 2147483648
2147483648 0 0 0 0 0 0 0 0
0 2147483648 0 0 0 0 0 0 0
0 0 2147483648 0 0 0 0 0 0
1 2 3 4 5 6 7 8 9
1000 200 1500 350 5000 1000 1000 2000 13000
5 10 5 20 10 5 10 20 10
60 20 1000 1000 60 20 10000 20 500
20 1000 50 2000 50 500 1500 20 3000
20 1000 50 2000 50 5000 1500 20 300

and this is the output:

BCG 30
CBG 50
BCG 0
BCG 0
GBC 0
CBG 0
BCG 30
BCG 6050
CBG 50
CGB 1620
GBC 2140
GCB 2440

Can anyone tell me what is wrong with it?

Final Sort Error

Posted: Sun Mar 26, 2006 9:03 am
by Rulojuka
I ve got AC.

I thought the final output should be in the order BGC,BCG,GBC...CGB, but its alphabetically... but now the problem is ok.

102 - WA

Posted: Mon Apr 17, 2006 10:12 am
by xopht
Could you please tell me what problem is on my code?

Code: Select all

#include <iostream>
#include <string>

using namespace std;

int take( int n, string* str, int* b, int sum )
{
    switch( n )
    {
        case 1:
            *str    = "BGC";
            return sum - b[ 0 ] - b[ 4 ] - b[ 8 ];
            break;
        case 2:
            *str    = "BCG";
            return sum - b[ 0 ] - b[ 5 ] - b[ 7 ];
            break;
        case 3:
            *str    = "GBC";
            return sum - b[ 1 ] - b[ 3 ] - b[ 8 ];
            break;
        case 4:
            *str    = "GCB";
            return sum - b[ 1 ] - b[ 5 ] - b[ 5 ];
            break;
        case 5:
            *str    = "CBG";
            return sum - b[ 2 ] - b[ 3 ] - b[ 7 ];
            break;
        case 6:
            *str    = "CGB";
            return sum - b[ 2 ] - b[ 4 ] - b[ 6 ];
            break;
    }
}

int main()
{
    int b[ 9 ];

    while( cin >> b[0] >> b[1] >> b[2] >> b[3] >> b[4] >> b[5] >> b[6] >> b[7] >> b[8] )
    {
        int move    = b[0] + b[1] + b[2] + b[3] + b[4] + b[5] + b[6] + b[7] + b[8];

        int     small   = -1;
        string  str;

        for( int i = 1; i <= 6; ++i )
        {
            int s;
            string  s2;
            s   = take( i, &s2, b, move );

            if( s < small || small == -1 )
            {
                small   = s;
                str     = s2;
            }
            else if( s == small && s2 < str )
            {
                str = s2;
            }
        }

        cout    << str << " " << small << endl;
    }

    return 0;
}

Posted: Thu May 18, 2006 1:30 am
by klam
since u've solve it can you actually help me with something? im running your test case, did you submit your program in the format:

input
input
output
output

or

input
output
input
output

i think mine is right but im getting WA
if you submited as the 1st one, does it end with a "end of line"?


EDITED: nvm, i found out how it works now.

Re: Problem is solved!

Posted: Thu May 18, 2006 1:53 am
by klam
jan-jun-john wrote:I can get AC!!!

Code: Select all

while (true) {
if (cin.eof()) break;
.
.
.
This is the cause of WA.
This should be changed,

Code: Select all

while (scanf("%d %d %d %d %d %d %d %d %d", 
			&data[0],&data[1],&data[2], 
			&data[3],&data[4],&data[5], 
			&data[6],&data[7],&data[8])==9) {...
so according to this.... the process goes:

input
output
input
output
input
output

am i right?
is there an end of line at the end? must be unless u bother to check where's the last line and output without endl/println

102 WA

Posted: Thu May 18, 2006 3:33 am
by himanshu
Hi XOPHT

I tried your code. It works fine on sample input. Could you figure out the problem. I think it is quite well written.

Himanshu

102 WA pls tell me where is the problem??????

Posted: Mon May 29, 2006 7:06 pm
by ayeshapakhi
here's the code...........

Thanks for any help.

the code is removed after getting AC

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

Code: Select all




for(i=0; i<N; i++)
		{			if(allcomb[i]<min)
			{
				strcpy(glass,col[i]);
				min=allcomb[i];			
			}
			else if(allcomb[i]==min)
			{
				if( strcmp(glass,col[i])==1) 
					strcpy(glass,col[i]);
			}
		}
		printf("%s %ld\n",glass,min);


Re: 102 WA pls tell me where is the problem??????

Posted: Tue May 30, 2006 8:39 am
by tan_Yui
Hi, ayeshapakhi.
I think the cause of WA is your strcmp usage.

Please change to
strcmp(glass,col)>0

Best regards.

Posted: Tue May 30, 2006 8:53 am
by ayeshapakhi
dear tan_Yui...
Thanks a tonnn for ur help.......
i got accepted at last!!!!! :D
i missed that point......
thanks again..
:D

Prob 102: help a beginner

Posted: Fri Jun 16, 2006 5:55 pm
by sathyashrayan
Dear group,
I am beginner and I will be happy if some body
define the term "minimize the number of bottles that are moved".

I get different answer when the arrangement of the bin is subtracted
with the total number of bottle taking all the 3 into account. Is that
what they mean by movement of bottles. Pls help. thanks

Posted: Sat Jun 17, 2006 3:01 pm
by sathyashrayan
Are the new commers not allowed? :(