银翔三轮摩托车多少钱:有关Pascal的问题,有兴趣的,能力强的,能力弱的,进来看看

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/29 22:01:22
1、寻找第K大数(t1.pas)
一堆数有N个,我想从大到小排成一排,从中挑出第K大的那个数进行采样分析请你帮忙挑出来。
Input:输入文件的第一行为二个整数N和K,表示整数的个数(N,K<=10000),下面第二行为N个整数,其值都在(-32768~32767)之间。
Output:输出文件只有一个数,为第K大整数

2、全排序问题(t2.pas)
将一个字符组全排序
Input
一个长度小于10的字符串,该字符串由数字1~9组成。字符不会重复出现。
Output
按数字在输入串中出现的次序从小到大的顺序输出该字符组的全排序
Sample Input
132
Sample Output
1 3 2
1 2 3
3 1 2
3 2 1
2 1 3
2 3 1

3、 核电站问题(t3.pas)
一个核电站有N个放核物质的坑,坑排列在一条直线上。如果连续M个坑中放入核物质,则会发生爆炸,于是,在某些坑中可能不放核物质。
任务:对于给定的N和M,求不发生爆炸的放置核物质的方案总数
Input:
输入文件只一行,两个正整数N,M( 1<N<50,2≤M≤5)
Output:
输出文件只有一个正整数S,表示方案总数。
Sample Input
4 3
Sample Output
13

4、爬山(t4.pas)
Rocky山脉有n个山峰,一字排开,从西向东依次编号为1, 2, 3, ……, n。每个山峰的高度都是不一样的。编号为i的山峰高度为hi。
小修从西往东登山。每到一座山峰,她就回头观望自己走过的艰辛历程。在第i座山峰,她记录下自己回头能看到的山峰数si。
何谓“能看到”?如果在第i座山峰,存在j<k<i,hj<hk,那么第j座山峰就是不可见的。除了不可见的山峰,其余的山峰都是可见的。
回家之后,小修把所有的si加起来得到S作为她此次旅行快乐值。现在n座山峰的高度都提供给你了,你能计算出小修的快乐值吗?
Input:
第一行一个整数n(n<=15000)。
第i+1(1<=i<=n)行是一个整数hi(hi<=109)。
Output format:
仅一行:快乐值。
Sample:
T3.in
5
2
1
3
5
9
T3.out
5

悬赏分高哦,做的题要附上题目号码,要有源程序哦!

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.

把第四题的标程给我看看 我的解法是O(N平方)的算法
肯定要超几组数据~~~

悬赏分d

T2.pas
做了一题简单点的,我用delphi来做的,delphi也是Pascal语言,用了两个控件,一个文本框(用来输入数字)和一个标签(输出数据):
var
i, j, k, l, p, temp: integer;
s, s2, s3: array[1..10] of integer;
str: string;
begin
l1.Caption := ''; //清空
p := length(e1.Text);
for k := 1 to p do
begin
s[k] := strtoint(midstr(e1.Text, k, 1)); //给数组付值 ,文本中的数字
s2[k] := strtoint(midstr(e1.Text, k, 1));
s3[k] := strtoint(midstr(e1.Text, k, 1));
end;

for i := 1 to p do //降序
for j := i + 1 to p do
begin
if s[i] < s[j] then
begin
temp := s[i];
s[i] := s[j];
s[j] := temp;
end;
end;

for i := 1 to p do //升序
for j := i + 1 to p do
begin
if s3[i] > s3[j] then
begin
temp := s3[i];
s3[i] := s3[j];
s3[j] := temp;
end;
end;

begin
for i := 1 to p do begin
l1.Caption := l1.Caption + inttostr(s2[i]);

for l := 1 to p do begin
if s[l] = s2[i] then continue;
l1.Caption := l1.Caption + ' ' + inttostr(s[l]);
end;
l1.Caption := l1.Caption + chr(13); //降序输出

for l := 1 to p do begin //升序输出
if s3[l] = s2[i] then continue;
str := str + ' ' + inttostr(s3[l]); //升序保存在str中
end;
l1.Caption := l1.Caption + inttostr(s2[i]) + str + chr(13);
str := '';
end;
end;
end;

第4题有O(N*log(N))的解法如下:

var a:array[0..15000] of integer;
i,j,n,s,x,count:longint;

function upper_bound(l,r,x:longint):longint;
var
m:longint;
begin
if (l > r)
then
begin result := l; exit end;
if (l = r)
then
begin result := l + ord(a[l]>=x); exit end;
m := (l+r) div 2;
if (a[m] >= x)
then
result := upper_bound(m+1,r,x)
else
result := upper_bound(l,m,x)
end;

begin
assign(input,'t3.in');
assign(output,'t3.out');
reset(input);
rewrite(output);
readln(n);
s:=0;
count := 0;
for i:=1 to n do
begin
readln(x);
inc(s,count);
j := upper_bound(1,count,x);
a[j] := x;
count := j;
end;
writeln(s);
close(input);
close(output);
end.