我的程序哪错了,老是AC不了?总是wrong anwser!!!
我的程序哪错了,老是AC不了?总是wronganwser!!!BoxofBricksTimeLimit:1000/1000MS(Java/Others)MemoryLim...
我的程序哪错了,老是AC不了?总是wrong anwser!!!
Box of Bricks
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 943 Accepted Submission(s): 213
Problem Description
Little Bob likes playing with his box of bricks. He puts the bricks one upon another and builds stacks of different height. “Look, I\'ve built a wall!”, he tells his older sister Alice. “Nah, you should make all stacks the same height. Then you would have a real wall.”, she retorts. After a little consideration, Bob sees that she is right. So he sets out to rearrange the bricks, one by one, such that all stacks are the same height afterwards. But since Bob is lazy he wants to do this with the minimum number of bricks moved. Can you help?
Input
The input consists of several data sets. Each set begins with a line containing the number n of stacks Bob has built. The next line contains n numbers, the heights hi of the n stacks. You may assume 1≤n≤50 and 1≤hi≤100.
The total number of bricks will be divisible by the number of stacks. Thus, it is always possible to rearrange the bricks such that all stacks have the same height.
The input is terminated by a set starting with n = 0. This set should not be processed.
Output
For each set, print the minimum number of bricks that have to be moved in order to make all the stacks the same height.
Output a blank line between each set.
Sample Input
6
5 2 4 1 7 5
0
Sample Output
Set #1
The minimum number of moves is 5.
Author
qianneng
#include<iostream>
#define N 50
using namespace std;
int main()
{int n,i,s[N],j=0;
double ave;
cin>>n;
while(n!=0){
int sum=0,k=0;
for(i=1;i<=n;++i){
cin>>s[i];
sum+=s[i];
}
ave=sum/n;
for(i=1;i<=n;++i){
if(s[i]>ave)k+=s[i]-ave;
}
cout<<"set #"<<++j<<endl<<"The minimum number of moves is " <<k<<'.'<<endl<<endl;
cin>>n;
}
return 0;
} 展开
Box of Bricks
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 943 Accepted Submission(s): 213
Problem Description
Little Bob likes playing with his box of bricks. He puts the bricks one upon another and builds stacks of different height. “Look, I\'ve built a wall!”, he tells his older sister Alice. “Nah, you should make all stacks the same height. Then you would have a real wall.”, she retorts. After a little consideration, Bob sees that she is right. So he sets out to rearrange the bricks, one by one, such that all stacks are the same height afterwards. But since Bob is lazy he wants to do this with the minimum number of bricks moved. Can you help?
Input
The input consists of several data sets. Each set begins with a line containing the number n of stacks Bob has built. The next line contains n numbers, the heights hi of the n stacks. You may assume 1≤n≤50 and 1≤hi≤100.
The total number of bricks will be divisible by the number of stacks. Thus, it is always possible to rearrange the bricks such that all stacks have the same height.
The input is terminated by a set starting with n = 0. This set should not be processed.
Output
For each set, print the minimum number of bricks that have to be moved in order to make all the stacks the same height.
Output a blank line between each set.
Sample Input
6
5 2 4 1 7 5
0
Sample Output
Set #1
The minimum number of moves is 5.
Author
qianneng
#include<iostream>
#define N 50
using namespace std;
int main()
{int n,i,s[N],j=0;
double ave;
cin>>n;
while(n!=0){
int sum=0,k=0;
for(i=1;i<=n;++i){
cin>>s[i];
sum+=s[i];
}
ave=sum/n;
for(i=1;i<=n;++i){
if(s[i]>ave)k+=s[i]-ave;
}
cout<<"set #"<<++j<<endl<<"The minimum number of moves is " <<k<<'.'<<endl<<endl;
cin>>n;
}
return 0;
} 展开
展开全部
#include<iostream>
#define N 50
using namespace std;
int main()
{
int n,i,s[N+1],j=0; //原s[N]
int ave; //原double abe
while((cin>>n) && n!=0) //原cin>>n; while(n!=0)
{
int sum=0,k=0;
for(i=1;i<=n;++i){
cin>>s[i];
sum+=s[i];
}
ave=sum/n;
for(i=1;i<=n;++i){
if(s[i]>ave)k+=s[i]-ave;
}
//你小子妈的眼睛就跟张屁眼上没区别,大小写区别看不见???!!!!!还有他TMD妈的可没说结尾补空行
//cout<<"set #"<<++j<<endl<<"The minimum number of moves is " <<k<<'.'<<endl<<endl;
cout<<(j>0?"\n":"")<<"Set #"<<++j<<endl<<"The minimum number of moves is " <<k<<'.'<<endl;
//删除cin>>n;
}
return 0;
}
#define N 50
using namespace std;
int main()
{
int n,i,s[N+1],j=0; //原s[N]
int ave; //原double abe
while((cin>>n) && n!=0) //原cin>>n; while(n!=0)
{
int sum=0,k=0;
for(i=1;i<=n;++i){
cin>>s[i];
sum+=s[i];
}
ave=sum/n;
for(i=1;i<=n;++i){
if(s[i]>ave)k+=s[i]-ave;
}
//你小子妈的眼睛就跟张屁眼上没区别,大小写区别看不见???!!!!!还有他TMD妈的可没说结尾补空行
//cout<<"set #"<<++j<<endl<<"The minimum number of moves is " <<k<<'.'<<endl<<endl;
cout<<(j>0?"\n":"")<<"Set #"<<++j<<endl<<"The minimum number of moves is " <<k<<'.'<<endl;
//删除cin>>n;
}
return 0;
}
追问
兄弟,每个测试用例之间要有一个空白行的。题目最后边说了,所以还要改这句:
cout<<"Set #"<<++j<<endl<<"The minimum number of moves is " <<k<<'.'<<endl<<endl;
这样就AC了。不过仍然感谢!!!
追答
Output a blank line between each set.
这句话的意思是每个case之间,并没说结尾。如果说结尾也补充空行后AC,只能说题设不严谨或者此话存在歧义(ACM上题目原话跟结果不一致,也不是一次两次的事情,我也麻木了)
展开全部
其他方面的特殊数据错误没仔细考虑,但是可以很明显看出来的错有一个:数组越界,s[N]下标范围是0-49,但是好几个循环的地方都有可能出现s[50],比如s[i]当i=n的时候,题目说了1≤n≤50,n是可以取到50的,这样就会越界。除了这个问题之外,不过系统提示WA的话应该还是有其他的问题没考虑到,比如特殊数据没考虑
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这句话的意思是每个case之间,并没说结尾。如果说结尾也补充空行后AC,只能说题设不严谨或者此话存在歧义ACM上题目原话跟结果不一致
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询