(阶段四1.3)UVA 11300 Spreading the Wealth(利用中位数来解决求某一个点到给定的n个点的距离的最小值)
来源:互联网 发布:苏州软件外包公司 编辑:程序博客网 时间:2024/05/29 17:58
/* * UVA_11300.cpp * * Created on: 2013年11月17日 * Author: Administrator */#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>using namespace std;const int maxn = 1000010;long long a[maxn];long long c[maxn];long long m;long long sum;long long x ;long long ans;int main(){int n;while(scanf("%d",&n)!=EOF){int i;sum = 0;for(i = 1 ; i <= n ; ++i){scanf("%lld",&a[i]);//初始金币sum += a[i];}m = sum/n;c[0] = 0;for(i = 1 ; i < n ; ++i){//求每个人实际给出的金币c[i] = c[i-1] + a[i] - m;}sort(c,c+n);x = c[n/2];ans = 0;for(i = 0 ; i < n ;++i){ans += abs(x - c[i] + 0.0);}printf("%lld\n",ans);//cout<<ans<<endl;}return 0;}
- (阶段四1.3)UVA 11300 Spreading the Wealth(利用中位数来解决求某一个点到给定的n个点的距离的最小值)
- uva 11300 Spreading the Wealth (中位数的应用)
- Uva---11300 F. Spreading the Wealth (数学推理)---与数列有关的最小值一般与中位数有关
- Uva 11300 - Spreading the Wealth(中位数距离)
- uva 11300Spreading 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 中位数 *
- (阶段四1.4)LA 3708 Graveyard(一个圆圈上有n个点,新加入m个点,求每个点的最小移动距离)
- [算法] 已知在平面坐标系内有N个点,求离开给定坐标距离最近的10个点
- 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(数学,中位数)
- Oracle 之 “ORA-00979:不是GROUP BY 表达式”
- Hadoop的Slots概念
- 《hadoop权威指南》学习笔记-MapReduce工作机制(上)
- UVa 382 Perfection (过剩数、完美数和亏数)
- struts 2 异常处理机制
- (阶段四1.3)UVA 11300 Spreading the Wealth(利用中位数来解决求某一个点到给定的n个点的距离的最小值)
- oracle之高级查询、子查询
- AtomicInteger简介
- HTTP协议请求
- win上eclipse链接hadoop集群
- java.io.file的绝对路径和相对路径
- sql之更新
- winxp死亡倒计时,大家快安装使用汉澳sinox!
- 数据中心的分布式UPS系统