UVA 591 Box of Bricks
来源:互联网 发布:客户无忧软件 编辑:程序博客网 时间:2024/06/15 19:39
UVA-591
题意:求最少要移动多少块使得所有的高度相同。
解题思路:求下平均数,超过的就是要移动的,超过的部分加起来。
/************************************************************************* > File Name: UVA-591.cpp > Author: Narsh > > Created Time: 2016年07月14日 星期四 09时51分06秒 ************************************************************************/#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>using namespace std;int a[60],n,v,k;int main () { int num=0; while (scanf("%d",&n) && n ) { v=k=0; for (int i = 1; i <= n; i++) { scanf("%d",&a[i]); v+=a[i]; } v/=n; for (int i = 1; i <= n; i++) if (a[i] > v) k+=a[i]-v; num++; printf("Set #%d\n",num); printf("The minimum number of moves is %d.\n\n",k); }}
0 0
- UVa 591 - Box of Bricks
- uva 591 - Box of Bricks
- Uva 591 - Box of Bricks
- uva 591 Box of Bricks
- uva 591 - Box of Bricks
- UVa 591 - Box of Bricks
- UVA 591 - Box of Bricks
- uva 591Box of Bricks
- UVa 591 - Box of Bricks
- UVA 591 Box of Bricks
- uva 591 - Box of Bricks
- uva 591 Box of Bricks
- UVa 591 - Box of Bricks
- UVA 591 Box of Bricks
- UVa 591 - Box of Bricks
- Uva 591 Box of Bricks
- UVA - 591 Box of Bricks
- UVa:591 - Box of Bricks
- 2016.07.13【初中部 NOIP提高组 】模拟赛C总结
- Android Library上传到JCenter仓库实践
- mongodb 分片集群切换单个分片副本集primary的正确步骤
- tcp/ip是什么
- 九大排序算法再总结
- UVA 591 Box of Bricks
- 11 数值的整数次方
- makefile总结 (可做手册使用)
- Spring—struts2整合
- Android N代码分析:requestLayout
- android studio 2.0 导入项目
- 兹瓷分裂合并的线段树~(Segment tree Beats!Ⅱ)
- SMB协议
- leetcode题解-242.Valid Anagram