[POJ1477]Box of Bricks
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 19503 | Accepted: 7871 |
Description

Input
The total number of bricks will be divisible by the number of stacks. Thus, it is always possible to rearrange the bricks such that all stacks have the same height.
The input is terminated by a set starting with n = 0. This set should not be processed.
Output
Output a blank line after each set.
Sample Input
- 6
- 5 2 4 1 7 5
- 0
Sample Output
- Set #1
- The minimum number of moves is 5.
Source
THINKING
贪心,先计算平均值,再扫描数组求出差值,注意句末的句号和组数之间的空行!
- var a:array[..] of longint;
- n,i,sum,summ,t:longint;
- begin
- summ:=;
- while true do
- begin
- fillchar(a,sizeof(a),);
- sum:=;
- t:=;
- readln(n);
- if n= then halt;
- for i:= to n do
- begin
- read(a[i]);
- inc(sum,a[i]);
- end;
- sum:=sum div n;
- for i:= to n do
- t:=abs(sum-a[i])+t;
- writeln('Set #',summ);
- writeln('The minimum number of moves is ',t div ,'.');
- writeln;
- inc(summ);
- end;
- end.
[POJ1477]Box of Bricks的更多相关文章
- HDOJ 1326. Box of Bricks 纯水题
Box of Bricks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- Box of Bricks最小移动砖块数目
Description Little Bob likes playing with his box of bricks. He puts the bricks one upon another and ...
- HDOJ(HDU) 2088 Box of Bricks(平均值)
Problem Description Little Bob likes playing with his box of bricks. He puts the bricks one upon ano ...
- HDOJ 1326 Box of Bricks(简单题)
Problem Description Little Bob likes playing with his box of bricks. He puts the bricks one upon ano ...
- 591 - Box of Bricks
Box of Bricks Little Bob likes playing with his box of bricks. He puts the bricks one upon another ...
- Box of Bricks
Box of Bricks Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- HDU 2088 Box of Bricks
http://acm.hdu.edu.cn/showproblem.php?pid=2088 Problem Description Little Bob likes playing with his ...
- HDU 2088 Box of Bricks(脑洞)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2088 Box of Bricks Time Limit: 1000/1000 MS (Java/Oth ...
- zoj 1251 Box of Bricks
Box of Bricks Time Limit: 2 Seconds Memory Limit: 65536 KB Little Bob likes playing with his bo ...
随机推荐
- html+ashx 缓存问题
最近采用html+ashx的方式做了一个项目的几个配置页面的功能,由于浏览器的缓存问题,每次更新数据提交后,页面总是不会刷新,也就是说除了第一次加载页面会向一般处理(ashx)拿数据外,其他情况都是优 ...
- 使用PHP导出Word文档的原理和实例
PHP操作Word文档的方法有很多,这里再为大家提供一种方法. 原理 一般,有2种方法可以导出doc文档,一种是使用com,并且作为php的一个扩展库安装到服务器上,然后创建一个com,调用它的方 ...
- SQL学习_查询重复数据和连接多个表数据的方法
进行数据库测试时需要根据不同场景查询数据,以便验证发现的问题是否为脏数据引起的.记录一下最近常用的查询方法: 1. 查询表中重复数据(id不同,多个字段值相同) select P1.* from pr ...
- OSG-3.4.0 简要说明(Readme)
欢迎来到OpenSceneGraph(OSG)世界. Welcome to the OpenSceneGraph (OSG). 对于项目最新信息, 以及如何编译和运行库和示例的更多细节, 可以查看OS ...
- vi/vim正则表达式
http://www.cnblogs.com/penseur/archive/2011/02/25/1964522.html 毋庸多言,在vim中正则表达式得到了十分广泛的应用. 最常用的 / 和 : ...
- Java应用程序可执行jar文件与服务器交互中文乱码
生成可执行jar文件后,直接双击打开应用,发送Http请求带有中文时,服务器接收到的中文乱码! 解决方式: 1.在cmd命令中执行javaw命令打开jar可执行应用: 打开cmd命令框,输入: jav ...
- java实现的JDBCTemplate工具
1.DButil import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; impor ...
- 用android-x86模拟器不能运行程序错误Tag:libc的问题
如果用的是x86的android模拟器,运行软件时一闪就关闭logcat中:类似:Fatal signal 11 (SIGSEGV) at 0x00000078 (code=1), thread 16 ...
- HDU 1160 FatMouse's Speed(DP)
点我看题目 题意 :给你好多只老鼠的体重和速度,第 i 行代表着第 i 个位置上的老鼠,让你找出体重越大速度越慢的老鼠,先输出个数,再输出位置. 思路 :看题的时候竟然脑子抽风了,看了好久愣是没明白题 ...
- POJ 3007 Organize Your Train part II(哈希链地址法)
http://poj.org/problem?id=3007 题意 :给你一个字符串,让你无论从什么地方分割,把这个字符串分成两部分s1和s2,然后再求出s3和s4,让你进行组合,看能出来多少种不同的 ...