1.
program xx2011_1;
var n,i,c:longint;ave,s:extended;
f:array[1..10000]of longint;
begin
read(n);ave:=0;
for i:=1 to n do begin
read(f[i]);
ave:=ave+f[i];
end;
ave:=ave/n;c:=0;
for i:=1 to n do
if f[i]<ave then c:=c+1;
writeln(ave:0:2,' ',c);
end.
输入:
5
73 76 83 91 77
输出:80.00 3
2.
program xx2011_2;
var n,i,x,p,s:longint;
begin
read(n,x);
s:=0;p:=1;
for i:=1 to n do begin
p:=p*x;
s:=s+p;
end;
writeln(s);
end.
输入:
15 2
输出:65534
3.
program xx2011_3;
const maxn=100000;
var
f:array[1..maxn]of longint;
stack:array[1..maxn,1..2]of longint;
n,i,j,h,t,last,x,s:longint;
begin
read(n);
for i:=1 to n do read(f[i]);
stack[1,1]:=1;
stack[1,2]:=n;
last:=2;
while last>1 do begin
last:=last-1;
h:=stack[last,1];
t:=stack[last,2];
i:=h;
j:=t;
x:=f[h];
while i<j do begin
while(i<j)and(f[j]<x) do j:=j-1;
if i<j then begin
f[i]:=f[j];
i:=i+1;
end;
while (i<j)and(f[i]>x) do i:=i+1;
if i<j then begin
f[j]:=f[i];j:=j-1;
end;
end;
f[i]:=x;
if(h<i-1) then begin
stack[last,1]:=h; stack[last,2]:=i-1;last:=last+1;
end;
if(i+1<t) then begin
stack[last,1]:=i+1;stack[last,2]:=t;last:=last+1;
end;
end;
s:=f[2]-f[1];
for i:=3 to n do s:=s+f[i]-f[i-1];
writeln(s);
end.
输入1:
3
20 10 30
输入2:
10
40 36 47 29 25 35 22 42 13 58
输出:-20
-45
4.
program xx2011_4;
var
n,a,b,c,d:longint;
procedure matric(var a,b,c,d:longint;n:longint);
var a1,b1,c1,d1,a2,b2,c2,d2,a3,b3,c3,d3:longint;
begin
if n=1 then begin a:=0;b:=1;c:=1;d:=1;exit;end;
matric(a1,b1,c1,d1,n div 2);
matric(a2,b2,c2,d2,n div 2);
a3:=a1*a2+b1*c2;
b3:=a1*b2+b1*d2;
c3:=c1*a2+d1*c2;
d3:=c1*b2+d1*d2;
if n mod 2=1 then begin
a:=b3;b:=a3+b3;c:=d3;d:=c3+d3;
end
else begin
a:=a3;b:=b3;c:=c3;d:=d3;
end;
end;
begin
read(n);
if n<3 then writeln(1)
else begin
matric(a,b,c,d,n-2);
writeln(c+d);
end;
end.
输入1:
3
输入2:
7
输出:2
21