Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 19503 | Accepted: 7871 |
Description
6 5 2 4 1 7 5 0
Set #1 The minimum number of moves is 5.
贪心,先计算平均值,再扫描数组求出差值,注意句末的句号和组数之间的空行!
var a:array[1..10000] of longint; n,i,sum,summ,t:longint; begin summ:=1; while true do begin fillchar(a,sizeof(a),0); sum:=0; t:=0; readln(n); if n=0 then halt; for i:=1 to n do begin read(a[i]); inc(sum,a[i]); end; sum:=sum div n; for i:=1 to n do t:=abs(sum-a[i])+t; writeln(‘Set #‘,summ); writeln(‘The minimum number of moves is ‘,t div 2,‘.‘); writeln; inc(summ); end; end.
原文:http://www.cnblogs.com/yangqingli/p/4889801.html