UVA - 591 Box of Bricks
2016-07-21 20:19
381 查看
2016-07-22
题目大意:移动方块使所有列一样高,一次一个,求移动次数。
解题思路:求平均数然后计算每列大于平均数的个数。
UVA - 591 Box of Bricks
题目大意:移动方块使所有列一样高,一次一个,求移动次数。解题思路:求平均数然后计算每列大于平均数的个数。
#include <iostream> #include <cstdio> using namespace std; int main() { int N = 0; int n; while ( scanf("%d",&n) != EOF && n ) { N++; int num[1000]; int sum = 0; int ave; int ans = 0; for (int i = 0; i < n; i++) { scanf("%d",&num[i]); sum += num[i]; } ave = sum / n; for (int i = 0; i < n; i++) { if ( num[i] > ave ) ans = ans + num[i] - ave; } cout << "Set #" << N << endl; cout << "The minimum number of moves is " << ans << "." << endl << endl; } return 0; }
相关文章推荐
- CodeForces597BRestaurant(sort+贪心)
- Codeforces 83B Doctor
- spring、spring mvc以及IOC的阅读
- 函数输出100全部素数(while 与 if 区别)
- 10分钟掌握XML、JSON及其解析
- HDU 1232 畅通工程 并查集
- 详解iOS中的数据存储
- The Python Tutorial - Input and Output
- CodeForces 454B Little Pony and Sort by Shift
- 【CodeForces】604A - Uncowed Forces(水)
- HDU 4267-Phage War-线段树
- myeclipse search查找打开第二个文件时第一个文件被关闭关闭
- MongoDB从不懂到装懂其三(Java操作MongoDB)
- Codeforces 84B Magical Array
- 进程与线程的一个简单解释
- [shell基础]——find命令
- Mac Homebrew安装php56 到phpstorm过程问题汇总
- 2016 Multi-University Training Contest 2 第一题Acperience
- startUml 破解
- C/C++笔记--程序内存分区分析