## 591 - Box of Bricks

All about problems in Volume 5. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

angga888
Experienced poster
Posts: 143
Joined: Sat Dec 21, 2002 11:41 am
Location: Indonesia
Hmm.. weird... It should be correct

Maybe you can check the error message from the email sent by the judge.

kckckc
New poster
Posts: 4
Joined: Thu Feb 10, 2005 1:52 pm
Thanks

I submit the same code for a few times and finally it "Accepted"

I don't know where the problem is but now is correct

J&Jewel
New poster
Posts: 50
Joined: Thu Jul 31, 2003 10:43 am
Contact:
This is a very interesting problem....
Suddenly may be the judge server some times show false...
I also solve a problem....yesterday it shows w/A.....today it shows ACC...
Very Interesting....
I hate Wrong Answer!

Phoenix dark
New poster
Posts: 1
Joined: Sun Aug 27, 2006 2:28 am
Contact:

### 591

Can anyone please tell me what's wrong with this code:

#include <stdio.h>

main()
{
int n,h[200],sum=0,sum2=0,h1[100000];
int k=0,i,j;

while(scanf("%d",&n) && n!=0)
{
for(i=0;i<n;i++)
{
scanf("%d",&h);
sum+=h;
}

sum=sum/n;

for(i=0;i<n;i++)
{
if(h-sum>0)
{
sum2+=(h-sum);
}
}
h1[k]=sum2;
k++;
sum=sum2=0;
}

for(j=0;j<k;j++)
{
printf("set #%d\n",j+1);
printf("The minimum number of moves is %d\n\n",h1[j]);
}

return 0;
}

thanks

kolpobilashi
Learning poster
Posts: 54
Joined: Mon Jan 02, 2006 3:06 am
Contact:
your mistake is:you take all the inputs together and then print their outputs, but actually this is not the usual style for uva problems.
here you'll have to take an input, then print its output,then take another input........this process will go on until the end of the file.
you can have a look on the sample code provided in this site.
http://online-judge.uva.es/problemset/data/p100.c.html

best regards.
Sanjana

ahah2002
New poster
Posts: 5
Joined: Mon Sep 18, 2006 4:09 pm

### 591

I really can't find any mistakes...Pls help me~~~

#include <iostream>
using namespace std;
int main(){
int count=0;
int block;
long sum;
long result;
long diff;
int i;

do{
sum=0;
result=0;
cin>>block;
if (block==0){
break;}
count++;
int a[block];
for (i=0;i<block;i++){
cin>>a;
sum+=a;
}

for (i=0;i<block;i++){
diff=a-sum/block;
if (diff>0){
result+=diff;}
}
cout<<"Set #"<<count<<endl;
cout<<"The minimum number of moves is "<<result<<endl<<endl;

} while (1);

return 0;
}

john_locke
New poster
Posts: 13
Joined: Sat Oct 07, 2006 6:42 pm
Contact:

### 591 with P.E

This is my code cant find why i get P.E
plz help me

#include<iostream>
using namespace std;
int main()
{
int i=1,k,h[100];

cin>>k;
while(k!=0)
{
int sum=0;
for(int j=0;j<k;j++)
{
cin>>h[j];
sum=sum+h[j];
}
int t=sum/k;
int s=0;
for(int j=0;j<k;j++)
{
if(h[j]>t)
s=s+(h[j]-t);
}
cout<<"Set #"<<i<<endl;
cout<<"The minimum number of moves is "<<s<<"."<<endl;
cin>>k;
i++;
}
return 0;
}

augustotorres
New poster
Posts: 4
Joined: Tue Oct 03, 2006 10:29 pm
Hey...

Try changing line

Code: Select all

``cout<<"The minimum number of moves is "<<result<<endl<<endl;``
with line

Code: Select all

``cout<<"The minimum number of moves is "<<result<<"."<<endl<<endl;``
Then, you'll get ACC

augustotorres
New poster
Posts: 4
Joined: Tue Oct 03, 2006 10:29 pm
Try changing line

Code: Select all

``cout<<"The minimum number of moves is "<<s<<"."<<endl;``
with line

Code: Select all

``cout<<"The minimum number of moves is "<<s<<"."<<endl<<endl;``
Good luck

Debashis Maitra
Learning poster
Posts: 62
Joined: Sun Jul 09, 2006 8:31 am
Location: University of Dhaka
Contact:
Akash chhoyar swopno
Dream to touch the sky

dorpon
New poster
Posts: 1
Joined: Sat Jan 06, 2007 9:35 pm

### 591

can any one plz tell me what is the prob in my following program
#include<stdio.h>
main()
{
int x[100],n,i,y,z,l,k,j=1;
while(1)
{
y=0; l=0;
scanf("%d",&n);
if(n==0)
break;
for(i=0;i<n;i++)
{
scanf("%d",&x);
y+=x;
}
z=y/n;
printf("set# %d\n",j);
for(i=0;i<n;i++)
{
if(x>z)
l+=(x-z);
}
printf("The minimum number of moves is: %d\n",l);
j++;
}
}

vijay03
New poster
Posts: 33
Joined: Wed Sep 13, 2006 6:46 pm
Contact:
Two things:

Code: Select all

``````
printf("set# %d\n",j);

``````
should be

Code: Select all

``````
printf("Set #%d\n",j);

``````
And you forgot this line:

Output a blank line after each set.

shumphreys
New poster
Posts: 6
Joined: Wed Mar 21, 2007 7:24 pm

### 591: PE problem ...

HI, Having eventually managed to get an AC I know get a PE. I know it's not a major issue but I'd like to clear up what I might have got wrong. I copy below the i/o parts of the cod ein the hope that someone will guide me.

With thanks

Code: Select all

``````cin >> stackTotal;
// outer loop only entered if the stack total is not zero
...
cin >> stacks[i];
...
// process the stuff and do some calculations
// print out the result
cout << endl << "Set #" << count << endl;
cout << "The minimum number of moves is " << answer << "." << endl << endl;
``````

abdullah<cse du>
New poster
Posts: 39
Joined: Mon Dec 04, 2006 2:18 pm
Contact:
Hi,

There is a wrong in your output section. Your output section is

Code: Select all

``````cin >> stackTotal;
// outer loop only entered if the stack total is not zero
...
cin >> stacks[i];
...
// process the stuff and do some calculations
// print out the result
cout << endl << "Set #" << count << endl;
cout << "The minimum number of moves is " << answer << "." << endl << endl;
``````
Change it to

Code: Select all

``````cout <<"Set #" << count << endl;
``````
ABDULLAH.

scott1991
New poster
Posts: 28
Joined: Fri Dec 07, 2007 11:41 pm
can someone please give me some help in speeding up my program as i'm getting tle...

Code: Select all

``````#include <iostream>

int main()
{
int n,h=0,average=0,moves=0,set=1;
int* heights = new int [60];
a:
scanf("%d",&n);
if(n<1)
{
return 0;
}
else
{
while(h<n)
{
scanf("%d",&heights[h]);
average+=heights[h];
h++;
}
h=0;
average=average/n;
while(h<n)
{
if(heights[h]>average)
{
moves+=heights[h]-average;
}
h++;
}
printf("Set #%d\nThe minimum number of moves is %d.\n\n",set,moves);
moves=0;set++;
goto a;
}
}``````
thanks