2019山东ACM省赛F题

原题地址
这道题很简单 , 题意就是说有n个筐子 , 里面有不定量的石头。然后作者想让你把所有筐子的石头给平均一下。
然后条件是:
1.Remove a stone from one of the non-empty buckets.
2.Move a stone from one of the buckets (must be non-empty) to any other bucket (can be empty).
自己在这里犯傻了, 把2里面的can be empty 理解成了只能往空的筐子里放石头。。。
然后就是自己数组开得太大了, 来了几次SF。。。
附上代码:

#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<set>
#include<cstring>
using namespace std;

int main()
{
	int t;
	cin >>t;
	while(t--){
        long long  a ;
        cin >>a;
        long long  b[a+1];
        memset(b,0,sizeof(b));
        long long sum=0;
        for(long long i=0;i<a;i++){
            cin >>b[i];
            sum +=b[i];
        }
        long long  Count=0;
        sum /=a;
        for(long long  i=0;i<a;i++){
            if(b[i]>sum){
                Count +=b[i] - sum;
            }
            /*else{
                Count +=sum - b[i];
            }*/

        }
        cout<<Count <<endl;
	}
	return 0;
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 18:35
简历上把1个月实习写成了3个月,会进行背调吗?
码农索隆:一个月有一个月的实习经历,三个月有三个月的实习经历
点赞 评论 收藏
分享
迟缓的斜杠青年巴比Q...:简历被投过的公司卖出去了,我前两天遇到过更离谱的,打电话来问我有没有意向报班学Java学习,服了,还拿我学校一个学长在他们那报班学了之后干了华为OD当招牌
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务