Output a blank line after each set.
591 - Box of Bricks
Moderator: Board moderators
591
help me!
I dont understand "Output a blank line after each set"
I tried
printf("Set #%d\nThe minimum number of moves is %d.\n\n",i+1,min);
but it didnt work
i cant find the bugs!
#include<stdio.h>
int main(){
int n[50][50],min=0,j,k,i=0,sum=0;
scanf("%d",&n[0]);
while(n[0]!=0){
for(j=1;j<=n[0];j++){
scanf("%d",&n[j]);
}
i++;
scanf("%d",&n[0]);
}
i=0;
while(n[0]!=0){
min=sum=0;
for(j=1;j<=n[0];j++){
sum+=n[j];
}
sum/=n[0];
for(j=1;j<=n[0];j++){
if(n[i][j]-sum>0)
min+=n[i][j]-sum;
}
printf("Set #%d\nThe minimum number of moves is %d.\n\n",i+1,min);
i++;
}
return 0;
}
Hi Orca,
Your output format is perfectly alright.
Your mistake is on the declaration of the array size. The problems says
1<=n<=50 and you declared the array as n[50][50]. You are trying to access n[][50] in your code but you can not do that. Change to n[50][51]
and you will get AC.
By the way instead of storing all the inputs, consider it one by one. That is take one set of input, process it, output the answer, and take the next set and so on. In this way it will take less memory and the coding becomes much more efficient.
Hope it helps.
Your output format is perfectly alright.
Your mistake is on the declaration of the array size. The problems says
1<=n<=50 and you declared the array as n[50][50]. You are trying to access n[][50] in your code but you can not do that. Change to n[50][51]
and you will get AC.
By the way instead of storing all the inputs, consider it one by one. That is take one set of input, process it, output the answer, and take the next set and so on. In this way it will take less memory and the coding becomes much more efficient.
Hope it helps.
thx a lot
i stored all of the input because the sample input of #591
is
6
5 2 4 1 7 5
0
if i do it one by one the input/output will be
6
5 2 4 1 7 5
Set #1
The minimum number of moves is 5.
....0
so i stored all of them and my input/output will be
6
5 2 4 1 7 5
0
Set #1
The minimum number of moves is 5.
591 wrong question?
hi. i am a bit confused on the problem. seems like the problem is asking what is the subtration or additions one have to do. But from what I understand, shouldn't it be only 3 moves?
5 2 4 1 7 5
1 2 3 4 5 6 <col>
avg is 4 so
column moving
7 -> 4 (3blks)
1 -> 2 (1blk)
6 -> 2 (1blk)
3 moves.
Is this problem is kinda like binpacking problem?
5 2 4 1 7 5
1 2 3 4 5 6 <col>
avg is 4 so
column moving
7 -> 4 (3blks)
1 -> 2 (1blk)
6 -> 2 (1blk)
3 moves.
Is this problem is kinda like binpacking problem?
591 - Box of Bricks
This problem seems to be easy but i don't really know why I get WA when I submit it. I have read all the posts about this problem, but I can't still understand what's wrong in this code. Can someone help me?
[c]#include "stdio.h"
int x, i, heights[51], z, number=1, media, moves=0;
int calc();
int main()
{
for(x=1; ; x++)
{
moves= 0;
scanf("%d", &number);
if(number==0)
return 0;
for(i=0; i<number; i++)
scanf("%d", &heights);
media = calc();
for(z=0; z<i; z++)
if(heights[z]-media>0)
moves+=heights[z]-media;
printf("Set #%d\nThe minimum number of moves is %d.\n\n",x,moves);
}
return 0;
}
int calc()
{
int a, b=0;
for(a=0; a<=i; a++)
b+=heights[a];
return b/i;
}[/c]
Thanks...
[c]#include "stdio.h"
int x, i, heights[51], z, number=1, media, moves=0;
int calc();
int main()
{
for(x=1; ; x++)
{
moves= 0;
scanf("%d", &number);
if(number==0)
return 0;
for(i=0; i<number; i++)
scanf("%d", &heights);
media = calc();
for(z=0; z<i; z++)
if(heights[z]-media>0)
moves+=heights[z]-media;
printf("Set #%d\nThe minimum number of moves is %d.\n\n",x,moves);
}
return 0;
}
int calc()
{
int a, b=0;
for(a=0; a<=i; a++)
b+=heights[a];
return b/i;
}[/c]
Thanks...
591...I got an Accepted P.E.
I got an Accepted P.E...But I didn't know why~~~
Can someone tell me???
[c]
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,i,b,sum,c,min,k;
scanf("%d",&a);
k=1;
while (a!=0)
{
int num[a],ans[a];
num[a]=0;
sum=0;
min = 0;
for (i=1;i<=a;i++)
{
scanf("%d",&b);
num=b;
sum = sum+num;
}
c = sum/a;
for (i=1;i<=a;i++)
{
ans=abs(num-c);
min=min+ans;
}
printf("Set #%d\n",k);
printf("The minimum number of moves is %d.\n\n",min/2);
k++;
scanf("%d",&a);
}
}[/c]
Can someone tell me???
[c]
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,i,b,sum,c,min,k;
scanf("%d",&a);
k=1;
while (a!=0)
{
int num[a],ans[a];
num[a]=0;
sum=0;
min = 0;
for (i=1;i<=a;i++)
{
scanf("%d",&b);
num=b;
sum = sum+num;
}
c = sum/a;
for (i=1;i<=a;i++)
{
ans=abs(num-c);
min=min+ans;
}
printf("Set #%d\n",k);
printf("The minimum number of moves is %d.\n\n",min/2);
k++;
scanf("%d",&a);
}
}[/c]
591:why-PE
can anyone pls tell me why i got PE on 591:
#include<stdio.h>
int main(void)
{
long b[50]; long c,i,avg,dif;long sum=0;long total=0;long s=0;
scanf("%ld",&c);
while(c!=0){ sum=0;
total=0;
for(i=0;i<c;i++){ scanf("%ld",&b);
sum=sum+b; }
avg= sum / c;
for(i=0;i<c;i++){ if (b > avg) {dif=b-avg; total=total+dif;
} }
s++;
printf("Set #%ld\n",s);
printf("The minimum number of moves is %ld.\n\n",total);
scanf("%ld",&c);
}
return 0;
}
#include<stdio.h>
int main(void)
{
long b[50]; long c,i,avg,dif;long sum=0;long total=0;long s=0;
scanf("%ld",&c);
while(c!=0){ sum=0;
total=0;
for(i=0;i<c;i++){ scanf("%ld",&b);
sum=sum+b; }
avg= sum / c;
for(i=0;i<c;i++){ if (b > avg) {dif=b-avg; total=total+dif;
} }
s++;
printf("Set #%ld\n",s);
printf("The minimum number of moves is %ld.\n\n",total);
scanf("%ld",&c);
}
return 0;
}
aaa
-
- Experienced poster
- Posts: 120
- Joined: Sat Nov 01, 2003 6:16 am
- Location: Dhaka (EWU)
591-Box of Bricks (Can you tell me why I get Compile ERROR)?
//591-Box of Bricks
//belows is my code
//Can you tell me why I get Compile ERROR ?
//Thanks
#include<stdio.h>
int main(void)
{
int set = 0,n,i,all,box[50],avg,move[100]={0};
while(scanf("%d",&n)==1)
{
all=avg=0;
if(n==0)break;
set++;
for(i=1;i<=n;i++)
{
scanf("%d",&box[i-1]);
all=all+box[i-1];
}
avg = all/n;
for(i=1;i<=n;i++)
{
if(box[i-1]>avg)
move[set-1] = move[set-1] + box[i-1] - avg;
}
}
for(i=1;i<=set;i++)
{
printf("Set #%d\n",i);
printf("The minimum number of moves is %d.\n\n",move[i-1]);
}
return 0;
}
//belows is my code
//Can you tell me why I get Compile ERROR ?
//Thanks
#include<stdio.h>
int main(void)
{
int set = 0,n,i,all,box[50],avg,move[100]={0};
while(scanf("%d",&n)==1)
{
all=avg=0;
if(n==0)break;
set++;
for(i=1;i<=n;i++)
{
scanf("%d",&box[i-1]);
all=all+box[i-1];
}
avg = all/n;
for(i=1;i<=n;i++)
{
if(box[i-1]>avg)
move[set-1] = move[set-1] + box[i-1] - avg;
}
}
for(i=1;i<=set;i++)
{
printf("Set #%d\n",i);
printf("The minimum number of moves is %d.\n\n",move[i-1]);
}
return 0;
}