探宝寻踪攻略:pascal里面assign,inc什么意思?

来源:百度文库 编辑:神马品牌网 时间:2024/04/27 21:48:23

assign(f,filename)
用来指定一个文件变量实际上对应文件系统中的哪个文件名。
inc(x,increment)
等价于x := x + increment,但是效率更高。

分配

1:
var a:array[1..10000] of longint;
n,k,i:longint;
procedure sort(l,r:longint);
var i,j,min,temp:longint;
begin
i:=l;j:=r;min:=a[(l+r) div 2];
repeat
while a[i]<min do inc(i);
while a[j]>min do dec(j);
if i<=j then
begin
temp:=a[i];a[i]:=a[j];a[j]:=temp;
inc(i);dec(j);
end;
until i>j;
if i<r then sort(i,r);
if j>l then sort(l,j);
end;
begin
assign(input,'t1.in');
assign(output,'t1.out');
reset(input);
rewrite(output);
readln(n,k);
for i:=1 to n do
readln(a[i]);
sort(1,n);
writeln(a[n-k+1]);
close(input);
close(output);
end.

{===============================================}
2:

var se:set of 0..9;
a:array[1..9] of byte;
f:array[1..9] of byte;
i,k,j,m,n:longint;
procedure print;
var i:integer;
begin
for i:=1 to n do
write(f[i]);
writeln;
end;
procedure try(x:integer);
var i,j,k:integer;
begin
for i:=1 to n do
if (not (i in se)) then
begin
f[x]:=i;
se:=se+[i];
if x<n then try(x+1) else print;
se:=se-[i];
end;
end;

begin
assign(input,'t2.in');
assign(output,'t2.out');
reset(input);
rewrite(output);
readln(n);
se:=[];
try(1);
close(input);
close(output);
end.

3:

const
maxn=50;
var
ans:array[0..maxn,2..5]of qword;
n,m:byte;
begin
assign(input,'input.in');
assign(output,'output.out');
reset(input);
rewrite(output);
for m:=2 to 5 do begin
ans[0,m]:=1;
for n:=1 to m-1 do
ans[n,m]:=ans[n-1,m]*2;
ans[m,m]:=ans[m-1,m]*2-1;
for n:=m+1 to maxn do
ans[n,m]:=ans[n-1,m]*2-ans[n-m-1,m];
end;
read(n,m);
writeln(ans[n,m]);
close(input);
close(output);
end.

4:

var a:array[0..15000] of integer;
i,j,k,l,n,m,s1,s,max:longint;
begin
assign(input,'t3.in');
assign(output,'t3.out');
reset(input);
rewrite(output);
readln(n);
s:=0;
for i:=1 to n do
readln(a[i]);
for i:=1 to n do
begin
max:=0;
s1:=0;
for j:=i-1 downto 1 do
if a[j]>max then begin max:=a[j-1];inc(s1);end;
inc(s,s1);
end;
writeln(s);
close(input);
close(output);
end.