UVA 11300 Spreading the Wealth(思维题)
来源:互联网 发布:c语言用什么软件编程 编辑:程序博客网 时间:2024/05/06 21:57
这题把一个一般问题转成了一个几何问题,思路参加白书第三题。
//// main.cpp// Richard//// Created by 邵金杰 on 16/9/28.// Copyright © 2016年 邵金杰. All rights reserved.//#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn=1000000+100;typedef long long ll;ll a[maxn],c[maxn];ll aabs(ll x) {return x>0?x:-x;}int main(){ int n; while(scanf("%d",&n)!=EOF) { ll tot=0; for(int i=1;i<=n;i++) {scanf("%lld",&a[i]);tot+=a[i];} ll 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 x=c[n/2]; ll ans=0; for(int i=0;i<n;i++) ans+=aabs(x-c[i]); printf("%lld\n",ans); } return 0;}
0 0
- 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
- 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
- c语言中的比较函数大家了解吗?分享一些经验
- Web调用FastReport的配置问题
- 原生二维码扫描
- B - Romantic 欧几里得
- 通过Vector中放置inputstream使分割流统一放置在SequenceInputStream合并
- UVA 11300 Spreading the Wealth(思维题)
- 3分钟让你学会如何用超级表格发布搜索,查询数据
- jquery-ui和jquery.datatable.js插件冲突
- ThreadPoolExecutor使用和思考-线程池大小设置与BlockingQueue的三种实现区别
- iOS Objective-C语法(isKindOfClass, isMemberOfClass,id)等
- 去除navigationBar的半透明效果
- C程序设计题目,比较有意思的问题分享
- D - Can't be easier 几何计算
- 第五周项目4-数制转换