program lx;
var
a:array[1..500] of integer;
i,j,k,m,n,s,p:integer;
begin
s:=0;
readln(n); m:=0;
for i:=1 to n do
begin
read(a[i]);
m:=m+a[i];
end;
p:=m div n;
if a[n]>p then
begin
inc(s);
a[n-1]:=a[n-1]+a[n]-p;
a[n]:=p;
end;
if a[n]<p then
begin
inc(s);
a[n-1]:=a[n-1]-(p-a[n]);
a[n]:=p;
end;
for i:=n-1 downto 2 do
begin
if a[i]>p then
begin
a[i-1]:=a[i-1]+a[i]-p;
a[i]:=p;
inc(s);
end;
if a[i]<p then
begin
inc(s);
a[i-1]:=a[i-1]-(p-a[i]);
a[i]:=p;
end;
end;
writeln(s);
end.
n,i,t:integer;ave,s,m:real;
begin
readln(n);
for i:=1 to n do read(a[i]);
s:=0;
for i:=1 to n do s:=s+a[i];
ave:=s/n;t:=0;
for i:=1 to n do
begin
if a[i]<ave then begin m:=a[i];a[i]:=ave;a[i+1]:=a[i+1]+m-ave;t:=t+1;end;
if a[i]>ave then begin m:=a[i];a[i]:=ave;a[i+1]:=a[i+1]+m-ave;t:=t+1;end;
end;
write(t);
end.
program winter;
var
a:array[0..100] of longint;
n,i,b,mo:longint;
begin
readln(n); a[0]:=0;
for i:=1 to n do
begin
read(a[i]);
a[0]:=a[0]+a[i];
end;
mo:=a[0] div n;
for i:=1 to n do
begin
if a[i]>mo then begin a[i+1]:=a[i+1]+a[i]-mo; b:=b+1; end;
if a[i]<mo then begin a[i+1]:=a[i+1]-mo+a[i]; b:=b+1; end;
end;
writeln(b);
end.
一个线性的模拟走一边就行了~~
Var
a:array[1..100]of integer;
tot:longint;
p:integer;
n:integer;
Ans:longint;
Procedure Init;
Var
i:integer;
Begin
Fillchar(a,sizeof(a),0);
Tot:=0;
Ans:=0;
p:=0;
Readln(n);
For i:=1 to n do
Begin
Read(a[i]);
Inc(Tot,a[i]);
End;
p:=Tot div n;
For i:=1 to n do
a[i]:=a[i]-p;
End;
Function Try:boolean;
Var
i:integer;
Begin
Try:=True;
For i:=1 to n do
IF a[i]<>0 then
Exit;
Try:=False;
End;
Procedure Print;
Begin
Writeln(Ans);
Halt;
End;
Procedure Main;
Var
i,j:integer;
Begin
i:=1;
j:=n;
IF Try=False then
Print;
While a[i]=0 do Inc(i);
While a[j]=0 do Dec(j);
Repeat
a[i+1]:=a[i]+a[i+1];
a[i]:=0;
Inc(Ans);
IF Try=False then
Print;
While a[i]=0 do Inc(i);
Until i>j;
End;
Begin
Init;
Main;
Print;
End.
{
long i,j,n,s=0,time=0;
long a[101]={0};
scanf("%ld",&n);
for(i=1;i<=n;i++)
{
scanf("%ld",&a[i]);
s+=a[i];
}
s=s/n;
for(i=1;i<n;i++)
{
if(a[i]!=s)
{
time++;
a[i+1]=a[i+1]+a[i]-s;
a[i]=s;
}
}
printf("%ld",time);
}
到处晾程序
program zp;
var
a:array[0..10000] of longint;
pj:longint;
i,j,k,m,n:longint;
begin
readln(n);
k:=0;
for i:=1 to n do begin
read(a[i]);
k:=k+a[i];
end;
pj:=k div n;
for i:=1 to n do begin
if a[i]>pj then begin a[i+1]:=a[i+1]+a[i]-pj; m:=m+1; end else begin
if a[i]<pj then begin a[i+1]:=a[i+1]-pj+a[i]; m:=m+1; end; end;
end;
writeln(m);
end.