Page 2 of 6

Posted: Tue Oct 28, 2003 12:29 pm
by Maarten
Did you notice this:
Output a blank line after each set.

591

Posted: Mon Dec 15, 2003 6:55 am
by orca
:-?
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;
}

Posted: Mon Dec 15, 2003 7:12 am
by sohel
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.
:wink:

Posted: Mon Dec 15, 2003 7:39 am
by orca
:D
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.

Posted: Mon Dec 15, 2003 8:06 am
by sohel
Congrats! 8)

But the judge will not see the input order. It will just write the output in anoter file and then compare it with that of the judge's. So it doesn't matter at which part of your code you write the ouput.
Bye.
:wink:

Posted: Mon Dec 15, 2003 8:56 am
by orca
:P

thx for telling me that

591 wrong question?

Posted: Sun Mar 28, 2004 9:07 am
by linh
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?

Posted: Sun Mar 28, 2004 9:39 am
by sohel
One move is equivalent to the displacement of one block.

So, 7->4 is 3 blocks which is actually three moves.

Hope it helps. :wink:

591 - Box of Bricks

Posted: Mon Jul 26, 2004 8:38 pm
by vadiu
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...

Posted: Tue Jul 27, 2004 6:02 am
by abishek
simple mistake i think
for(a=0; a<=i; a++)
b+=heights[a[;
that is a<i i think.

Posted: Tue Jul 27, 2004 9:42 am
by vadiu
Thanks a lot. I got AC. :D

591...I got an Accepted P.E.

Posted: Mon Aug 02, 2004 10:58 am
by Wei
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]

591:why-PE

Posted: Sun Apr 10, 2005 4:13 pm
by 59557RC
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;
}

Posted: Sun Apr 10, 2005 4:52 pm
by mohiul alam prince
Hi
i have submited ur program and got AC without PE.
this is a ok program which u have posted for problem 591

MAP

591-Box of Bricks (Can you tell me why I get Compile ERROR)?

Posted: Thu Jul 28, 2005 9:53 am
by kckckc
//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;
}