11300 - Spreading the Wealth
来源:互联网 发布:淘宝投诉电话人工服务 编辑:程序博客网 时间:2024/06/15 01:58
题目地址https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=456&problem=2275&mosmsg=Submission+received+with+ID+18678435
#include<iostream>#include<cstdio>#include<cmath>#include<algorithm> using namespace std; int main() { long long n,people[1000000],total=0,average=0,c[1000000],x1,ans=0; while(scanf("%lld",&n)==1&&n) { total=average=ans=0; for(int i=0;i<n;i++) { scanf("%lld",&people[i]);total+=people[i]; } average=total/n; c[0]=abs(people[0]-average); for(int i=1;i<n;i++) { //c[i]=c[i-1]+abs(people[i]-average); c[i]=c[i-1]+people[i]-average; } sort(c,c+n); x1=c[n/2]; for(int i=0;i<n;i++)ans+=abs(x1-c[i]); printf("%lld\n",ans); } return 0; }
0 0
- 11300 - Spreading the Wealth
- 11300Spreading the Wealth
- 11300 - Spreading the Wealth
- 11300 - Spreading the Wealth
- 11300 - Spreading the Wealth
- Uva - 11300 - Spreading the Wealth
- uva 11300 - Spreading the Wealth
- Uva-11300-Spreading the Wealth
- UVA 11300 Spreading the Wealth
- UVa 11300 - Spreading the Wealth
- uva 11300 Spreading the Wealth
- UVA 11300 Spreading the Wealth
- uva 11300 Spreading the wealth
- UVA - 11300 Spreading the Wealth
- UVa 11300 Spreading the Wealth
- UVA 11300 Spreading the Wealth
- UVa 11300 Spreading the Wealth
- UVA 11300 Spreading the Wealth
- CORDOVA介绍
- 玩转spring boot——结合阿里云持续交付_0
- 洛谷 P1282 多米诺骨牌
- 在C++中子类继承和调用父类的构造函数方法
- Centos7 下zookeeper3.4.9集群搭建
- 11300 - Spreading the Wealth
- HTML基础知识
- study-26:XenServer应用
- 我的渗透学习实验(一)
- ZooKeeper Watcher代码实例
- 用Mockito测试SpringMVC+Hibernate
- 欢迎使用CSDN-markdown编辑器
- Leetcode 27. Remove Element
- 算法里面的渐近记号