- 均分纸牌
- 2014-12-12 18:43:29 @
var
i,n,k,b:integer;
a:array[1..100] of longint;
begin
readln(n);
b:=0;
for i:=1 to n do
begin
read(a[i]);
k:=k+a[i];
end;
k:=k div n;
for i:=1 to n do
a[i]:=a[i]-k;
for i:=1 to n do
if a[i] =0 then continue
else
begin
a[i+1]:=a[i+1]+a[i]; a[i]:=0; b:=b+1;
end;
writeln(b);
end.
3 条评论
-
hahayang LV 10 @ 2016-12-11 15:22:14
其实第五个点用longint就过了。而且不用0也可以。
var
a:array[1..100] of longint;
n, i, x, s:longint;
begin
readln(n);
for i:=1 to n do read(a[i]);
x:=0;
for i:=1 to n do inc(x, a[i]);
x:=x div n;
s:=0;
for i:=1 to n-1 do if a[i]<>x then begin
a[i+1]:=a[i]+a[i+1]-x;
inc(s)
end;
write(s)
end. -
2016-10-31 12:55:22@
可能是因为中途遇到了这种情况——
.......9,0,0,-2.........
此时的正解应该是把9->2,但你的是9->0->0->2,所以没过吧。。。 -
2014-12-14 16:59:36@
不一定要用0表示刚好嘛- -很简单的思路就是从1到最后,多了牌的人把多出来的给别人,少牌的就去取。
你这程序思路正确,应该某些特殊情况没考虑。我的程序你可以看看- -
program ex;
var data:array[0..101] of longint;
n,num,a,i,j,sum,avg,step:longint;
begin
fillchar(data,sizeof(data),0);
sum:=0; avg:=0; step:=0;
read(n);for i:=1 to n do
begin
read(num);
data[i]:=num;
sum:=sum+num;
end;avg:=sum div n;
for i:=1 to n do
begin
if data[i]<avg then
begin
step:=step+1;
data[i+1]:=data[i+1]-(avg-data[i]);
data[i]:=avg;
end;
if data[i]>avg then
begin
step:=step+1;
data[i+1]:=data[i+1]+(data[i]-avg);
data[i]:=avg;
end;
if data[i]=avg then
continue;
end;write(step);
end.
- 1