讨论 / 为什么第5.10 组不过啊?
liulei626 2012-12-19 02:37:00
点我顶贴 收藏 删除
程序如下

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.

#1 白白@2008-12-04 07:35:00
回复 删除
直接比两次就行吧,弄平均数,然后扫,如果比平均数大的怎么,怎么样,如果比平均小的怎么怎么样~

#2 shuizilong96@2008-12-04 08:10:00
回复 删除
var a:array[1..100000] of real;

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.

#3 冬日的雪花@2008-12-04 18:35:00
回复 删除
不会这么麻烦阿

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.

一个线性的模拟走一边就行了~~

#4 shuizilong96@2008-12-06 07:33:00
回复 删除
只看第一个,

#5 king13@2008-12-19 04:01:00
回复 删除
就是一个贪心

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.

#6 why19931123@2009-01-03 01:18:00
回复 删除
纯模拟拉

很Easy的

#7 why19931123@2009-01-03 01:18:00
回复 删除
纯模拟拉

很Easy的

#8 w122185976@2009-01-14 03:32:00
回复 删除
又不用输出过程,很简单的拉,先用每个数减去平均数,然后就很容易拉!!!!
#9 zrp@2009-01-16 18:38:00
回复 删除
main()

{

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);

}

#10 hades@2009-02-27 01:45:00
回复 删除
无聊中……

到处晾程序

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.

查看更多回复
提交回复