591 - Box of Bricks
Moderator: Board moderators
i thought i did with
if this wasn't initializing 'average', what is please? cheers.
Code: Select all
int n,h=0,average=0,moves=0,set=1;
Re: acm-591 prob
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
Regards
Tarif
Tarif Ezaz
Undergraduate student
North South University
12 Kamal Ataturk Avenue, Dhaka
Undergraduate student
North South University
12 Kamal Ataturk Avenue, Dhaka
-
- New poster
- Posts: 2
- Joined: Tue Feb 12, 2008 8:52 pm
Re: acm-591 prob
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
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
-
- New poster
- Posts: 21
- Joined: Wed Oct 08, 2008 7:04 am
To "vinocit"
Hi.
This is an easy problem.
But please be careful about its output standard.
That's why you get WA.
You didn't put any blank line after them.
I have tested for you.
if this line
changes to
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.
This is an easy problem.
But please be careful about its output standard.
Code: Select all
Output a blank line after each set.
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";
Code: Select all
cout<<"The minimum number of moves is "<<mov<<".\n\n";
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.
-
- Experienced poster
- Posts: 136
- Joined: Sat Nov 29, 2008 8:01 am
- Location: narayangong,bangladesh.
- Contact:
why wa??
i got wa.
but i cant understand why!!!!!
anyone help plz.
my code
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;
}
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
-
- Experienced poster
- Posts: 136
- Joined: Sat Nov 29, 2008 8:01 am
- Location: narayangong,bangladesh.
- Contact:
Re: 591
thanx to articuno for ur help.
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
-
- New poster
- Posts: 2
- Joined: Mon Feb 09, 2009 7:41 pm
Re: 591
I got RE why? thanks everyone!
![:wink:](./images/smilies/icon_wink.gif)
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
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;
}
#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
Hi!
Just got AC![:)](./images/smilies/icon_smile.gif)
Some tips:
Wish you luck ![:)](./images/smilies/icon_smile.gif)
Just got AC
![:)](./images/smilies/icon_smile.gif)
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 )
![:)](./images/smilies/icon_smile.gif)