UVa 11300 找金币
来源:互联网 发布:陕西省中小学网络竞赛 编辑:程序博客网 时间:2024/05/24 05:35
题目:https://cn.vjudge.net/problem/UVA-11300
经过分析,转化为找中位数
#include<bits/stdc++.h>using namespace std;typedef long long int ll;const int maxn=1000000+10;ll A[maxn],C[maxn],tot,M;int main(){ int n; while(scanf("%d",&n)==1){ tot=0; for(int i=1;i<=n;i++){ scanf("%lld",&A[i]); tot+=A[i]; } M=tot/n; C[0]=0; for(int i=1;i<n;i++) C[i]=C[i-1]+A[i]-M; sort(C,C+n); ll x1=C[n/2],ans=0; for(int i=0;i<n;i++) ans+=fabs(x1-C[i]); printf("%lld\n",ans); } return 0;}
阅读全文
0 0
- UVa 11300 找金币
- uva 11300 分金币
- uva 11300 分金币
- uva 11300(分金币)
- 【贪心+中位数】【UVa 11300】 分金币
- UVa 11300 Spreading the Wealth 分金币
- UVA 11300 Spreading the Wealth 分金币
- 机器人找金币
- 分而治之-找金币
- (uva 11300)分金币(Spreading the Wealth)
- Uva 11300 分金币(数学推导和中位数)
- UVa 11300 Spreading the Wealth 分金币 (中位数)
- 第一章例题3分金币UVa 11300(中位数)
- 中位数-分金币(Spreading the Wealth, UVa 11300)
- 分金币(Spreading the Wealth, UVa 11300)
- 【两个智力题】金币测重量,找假币
- 分金币(Spreading the Wealth, UVa 11300)【JAVA算法实现】
- [训练指南] 第一章 例题3 分金币 (Spreading the wealth,Uva 11300)
- 深入理解Java中的final关键字
- java中反射的作用及用法
- 15届走美杯真题及答案汇总
- 我的微信公众号开发学习整理
- 版本一致问题
- UVa 11300 找金币
- selenium+python实现1688登录 —— iframe中元素获取
- CDH Upgrade 5.10.0-->5.11.0
- 谨慎对待spider蜘蛛提升网站收录比
- matlab_3_图像处理_空间滤波
- spring,mybatis事务管理配置
- 使用IntelliJ IDEA 配置Maven
- 上海 “东方购物”面试总结
- 【思维导图】03-数据挖掘绪论