1.
const
SIZE=100;
var
n,i,sum,x:integer;
A:array[1..SIZE]of integer;
begin
readln(n);
fillchar(a,sizeof(a),0);
for i:=1 to n do
begin
read(x);
inc(a[x]);
end;
i:=0;
sum:=0;
while sum<(n div 2 + 1) do
begin
inc(i);
sum:=sum+a[i];
end;
writeln(i);
end.
输入:
11
4 5 6 6 4 3 3 2 3 2 1
输出:3
2.
var
n:integer;
procedure f2(x,y:integer);
forward;
procedure f1(x,y:integer);
begin
if x<n then
f2(y,x+y);
end;
procedure f2(x,y:integer);
begin
write(x,’ ‘);
f1(y,x+y);
end;
begin
readln(n);
f1(0,1);
end.
输入:30
输出:1 2 5 13 34
3.
const
v = 100;
var
visited:array[1..v]of boolean;
e:array[1..v,1..v]of integer;
n,m,ans,i,j,a,b,c:integer;
procedure dfs(x,len:integer);
var
i:integer;
begin
visited[x] := true;
if len > ans then
ans:=len;
for i:=1 to n do
if (not visited(i)) and(e[x,i] <> -1) then
dfs(I,len+e[x,i]);
visited[x] := false;
end;
begin
readln(n,m);
for i:=1 to n do
for j:=1 to n do
e[i][j] := -1;
for i:=1 to m do
begin
readln(a,b,c);
e[a][b]:=c;
e[b][a]:=c;
end;
for i:=1 to n do
visited[i]:=false;
ans:=0;
for i:=1 to n do
dfs(i,0);
writeln(ans);
end.
输入:
4 6
1 2 10
2 3 20
3 4 30
4 1 40
1 3 50
2 4 60
输出:150
4.
const
SIZE = 10000;
LENGTH = 10;
var
sum : longint;
n,m,I,j : integer;
a:array[1..SIZE , 1..LENGTH]of integer;
function h(u , v :integer):integer;
var
ans,i : integer;
begin
ans:=0;
for i:=1 to n do
if a[u][i] <> a[v][i] then
inc(ans);
h := ans;
end;
begin
readln(n);
fillchar(a,sizeof (a),0);
m:=1;
repeat
i := 1;
while (i <=n) and (a[m][i] =1 ) do
inc(i);
if i>n then
break;
a[m][i]:=1;
for j:=i + 1 to n do
a[m][j] := a[m-1][j];
until false;
sum := 0;
for i := 1 to m do
for j := 1 to m do
sum := sum + h(i,j);
writeln(sum);
end.
输入:7
输出:57344