Page 4 of 6

Posted: Mon Mar 10, 2008 1:21 am
by Jan
You forgot to initialize 'average'.

Posted: Mon Mar 10, 2008 8:35 pm
by scott1991
i thought i did with

Code: Select all

int n,h=0,average=0,moves=0,set=1;
if this wasn't initializing 'average', what is please? cheers.

Re: acm-591 prob

Posted: Thu Jul 10, 2008 12:49 pm
by Tarif
I need a bit help in this. If the number of bricks in one line is more than 100, what would happen? Should we just ignore that input and go for the next one or we escape that set of inputs. please help!

Regards
Tarif

Re: acm-591 prob

Posted: Sat Jul 12, 2008 9:40 pm
by Raffan_033
Can any one plz help with the code?i donno whats wrong.
i'm stuck for a very very very long time with this problem.

#include<stdio.h>

int main(void)
{
int stack_height[50]={0};
int n,total_height,average_height,move,count=1,i;


while(scanf("%d",&n)==1)
{

if((n<1)||(n>50))
break;

move=0;
total_height=0;
for(i=0;i<n;i++)
{
scanf("%d",&stack_height[i]);

if((stack_height[i]<1)||(stack_height[i]>100))
break;;

total_height+=stack_height[i];
}


if((total_height%n)!=0)
break;

average_height=total_height/n;

for(i=0;i<n;i++)
{
if(stack_height[i]>average_height)
move+=(stack_height[i] - average_height);
}

printf("Set #%d\n",count);
printf("The minimun number of moves is %d.\n",move);

count++;
}
return 0;
}

Raffan

Re: 591

Posted: Mon Oct 13, 2008 11:30 am
by vinocit
Hi does anyone know wats wrong in my code :(
I am getting WA

Code: Select all

Removed after AC

To "vinocit"

Posted: Tue Nov 04, 2008 1:08 pm
by porker2008
Hi.
This is an easy problem.
But please be careful about its output standard.

Code: Select all

Output a blank line after each set. 
That's why you get WA.
You didn't put any blank line after them.

I have tested for you.
if this line

Code: Select all

cout<<"The minimum number of moves is "<<mov<<".\n";
changes to

Code: Select all

cout<<"The minimum number of moves is "<<mov<<".\n\n";
your code will be accepted.

So please remember to remove your code because it's nearly accepted.

BTW,"Raffan_033" also forgot to put a blank line after each case. However, after I add it for him/her, it still get WA.

Best regards.

Re: 591

Posted: Wed Nov 12, 2008 7:27 am
by vinocit
Thanks i got ACed :D

why wa??

Posted: Thu Dec 18, 2008 9:29 pm
by sazzadcsedu
i got wa.

but i cant understand why!!!!!
anyone help plz.
my code

Code: Select all


         #include<stdio.h>
         #include<stdlib.h>

       int main()

    {  
       int s[100];      
       int n;
       int sum;
       int avg;
       int mv;
       int i,ncase=0;

      while(scanf("%d",&n)==1)
	  {
	    if(n==0)
         break;

		ncase++;
	   sum=0;
       for(i=0;i<n;i++){
       scanf("%d",&s[i]);
      sum=sum+s[i];
      }

       avg=sum/n;
   
       mv=0; 
       for(i=0;i<n;i++)
      {  
       if(s[i]<avg)
     
       mv=mv+(avg-s[i]); 

      }
       printf("Set #%d\n",ncase);
       printf("The minimum number of moves is %d\n\n",mv); 

	   

		}

	    

	     return 0;
      }  

Re: 591

Posted: Fri Dec 19, 2008 8:23 am
by Articuno
Your code is OK. But you forgot to print a '.' in the output.

Re: 591

Posted: Fri Dec 26, 2008 9:21 pm
by sazzadcsedu
thanx to articuno for ur help.

Re: 591

Posted: Tue Feb 17, 2009 3:40 am
by metalcarryon
I got RE why? thanks everyone! :wink:

Code: Select all

#include <stdio.h>
#include <stdlib.h>

int compare (const void * a, const void * b);

int compare (const void * a, const void * b)  //compara inteiros
{
  return ( *(int*)a - *(int*)b );
}

int main ()
{
  int i,j,k,temp;
  int quantidade = 0;
  int vetor[55];
  int quantum = 0;
  int cont = 0;
  int vezes = 0;
  
  while(scanf("%d",&quantidade)==1){                 //começa o while
  cont = 0;
  temp = 0;
  quantum = 0;
  for(j = 0;j<quantidade;j++){
  		
		  scanf("%d",&temp);
		  vetor[j] = temp;
		  quantum = quantum + temp;		//estabeleço o quantum
		  }
		  quantum = quantum/quantidade;		  		   		   	 	  	  						 		  
  for(k=0;k<55;k++){                   //for semi-infinito
  
  qsort (vetor, quantidade, sizeof(int), compare);
  
  while(vetor[quantidade-1]>quantum){
		vetor[quantidade-1] = vetor[quantidade-1] - 1;
		cont = cont + 1;
  		  
			}
  
  
  if(vetor[quantidade-1]== vetor[0]) break;      //se primeiro elemento = ultimo, entao acabou!
}															//terminda for semi-infinito
   vezes = vezes + 1;
   printf("Set #%d\nThe minimum number of moves is %d.\n",vezes,cont);
  
  
}													//termina o while que comanda o programa
  
  return 0;
}			//termina main()



Re: 591

Posted: Wed Feb 18, 2009 4:46 pm
by helloneo
When quantidade = 0 ..

Code: Select all

quantum = quantum/quantidade;      <------ divide by 0 ???
:-)

Re: 591

Posted: Thu Jul 02, 2009 4:27 pm
by mhn
i m getting wa..y??can anyone plz help me....

#include<stdio.h>

int main(){

int x[100],n,sum,a,b,i,j=1;

while(scanf("%d",&n)==1)
{sum=0;
b=0;
if(n!=0 && n>=1 && n<=50)
{
for(i=0;i<n;i++)
{
scanf("%d",&x);
if(x>=1 && x<=100)
{
sum=sum+x ;
}
else break;
}
if(sum%n==0)
{
a=sum/n;
for(i=0;i<n;i++)
{
if(x>a) b=b+x-a;
else continue;
}
} else break;

printf("Set #%d\n",j++);
printf("The minimum number of moves is %d\n",b);
}

else break;
}
return 0;
}

Re: 591

Posted: Mon Sep 06, 2010 2:33 pm
by valkov
Hi!
Just got AC :)
Some tips:

Code: Select all

1. Find the average height:
total sum / number of towers
2. Sort the towers in asc order
(for C++ guys, use <algorithm> sort() with vector or array if you want to get it done quickly)
3. For each tower with height > average:
       moves += tower height - average
4. Print the moves as specified in the problem ( read carefully and output blank line after EACH set )
Wish you luck :)

Re: 591

Posted: Tue Sep 07, 2010 8:50 pm
by faiem
why u r sorting???
it is possible without sorting...and very fast...