pascal程序会超3m的内存吗? 20
programfind;vars:array[0..100010]ofansistring;b,c:array[0..100010]oflongint;st:string...
program find;
var
s:array[0..100010] of ansistring;
b,c:array[0..100010] of longint;
st:string;
qwe,cur,sum,i,ii,j,k,n,q,jj:longint;
x,y:int64;
rr:double;
procedure qsort(l,r:longint);
var
i,j,x,y,t:longint;
st:ansistring;
begin
i:=l;
j:=r;
x:=b[(i+j) div 2];
repeat
while b[j]>x do dec(j);
while b[i]<x do inc(i);
if i<=j then
begin
t:=b[i];
b[i]:=b[j];
b[j]:=t;
t:=c[i];
c[i]:=c[j];
c[j]:=t;
st:=s[i];
s[i]:=s[j];
s[j]:=st;
inc(i);
dec(j);
end;
until i>j;
if i<r then qsort(i,r);
if j>l then qsort(l,j);
end;
procedure wbsort(l,r:longint);
var
i,j,x,y,t:longint;
st:ansistring;
begin
i:=l;
j:=r;
x:=c[(i+j) div 2];
repeat
while c[j]>x do dec(j);
while c[i]<x do inc(i);
if i<=j then
begin
t:=c[i];
c[i]:=c[j];
c[j]:=t;
st:=s[i];
s[i]:=s[j];
s[j]:=st;
inc(i);
dec(j);
end;
until i>j;
if i<r then wbsort(i,r);
if j>l then wbsort(l,j);
end;
begin
assign(input,'find.in');
assign(output,'find.out');
reset(input);
rewrite(output);
readln(n,k);
dec(k);
for i:=1 to n do
begin
readln(st);
q:=pos(' ',st);
s[i]:=copy(st,1,q-1);
delete(st,1,q);
while pos('-',st)<>0 do
delete(st,pos('-',st),1);
q:=pos(' ',st);
val(copy(st,1,q-1),x,qwe);
val(copy(st,q+1,10),y,qwe);
rr:=sqrt(x*x+y*y);
b[i]:=trunc(rr*10000);
c[i]:=i;
end;
qsort(1,n);
cur:=b[1];
sum:=1;
jj:=0;
for i:=2 to n do
if b[i]<>cur then
begin
if sum=k then
begin
jj:=i;
break;
end;
cur:=b[i];
inc(sum);
end;
b[n+1]:=-1;
if jj=0 then
writeln('555...')
else
begin
cur:=b[jj];
for i:=jj+1 to n-1 do
if b[i]<>cur then
begin
ii:=i;
break;
end;
cur:=trunc(b[jj]/10000);
writeln(cur,' ',ii-jj);
wbsort(jj,ii-1);
for i:=jj to ii-1 do
writeln(s[i]);
end;
close(input);
close(output);
end. 展开
var
s:array[0..100010] of ansistring;
b,c:array[0..100010] of longint;
st:string;
qwe,cur,sum,i,ii,j,k,n,q,jj:longint;
x,y:int64;
rr:double;
procedure qsort(l,r:longint);
var
i,j,x,y,t:longint;
st:ansistring;
begin
i:=l;
j:=r;
x:=b[(i+j) div 2];
repeat
while b[j]>x do dec(j);
while b[i]<x do inc(i);
if i<=j then
begin
t:=b[i];
b[i]:=b[j];
b[j]:=t;
t:=c[i];
c[i]:=c[j];
c[j]:=t;
st:=s[i];
s[i]:=s[j];
s[j]:=st;
inc(i);
dec(j);
end;
until i>j;
if i<r then qsort(i,r);
if j>l then qsort(l,j);
end;
procedure wbsort(l,r:longint);
var
i,j,x,y,t:longint;
st:ansistring;
begin
i:=l;
j:=r;
x:=c[(i+j) div 2];
repeat
while c[j]>x do dec(j);
while c[i]<x do inc(i);
if i<=j then
begin
t:=c[i];
c[i]:=c[j];
c[j]:=t;
st:=s[i];
s[i]:=s[j];
s[j]:=st;
inc(i);
dec(j);
end;
until i>j;
if i<r then wbsort(i,r);
if j>l then wbsort(l,j);
end;
begin
assign(input,'find.in');
assign(output,'find.out');
reset(input);
rewrite(output);
readln(n,k);
dec(k);
for i:=1 to n do
begin
readln(st);
q:=pos(' ',st);
s[i]:=copy(st,1,q-1);
delete(st,1,q);
while pos('-',st)<>0 do
delete(st,pos('-',st),1);
q:=pos(' ',st);
val(copy(st,1,q-1),x,qwe);
val(copy(st,q+1,10),y,qwe);
rr:=sqrt(x*x+y*y);
b[i]:=trunc(rr*10000);
c[i]:=i;
end;
qsort(1,n);
cur:=b[1];
sum:=1;
jj:=0;
for i:=2 to n do
if b[i]<>cur then
begin
if sum=k then
begin
jj:=i;
break;
end;
cur:=b[i];
inc(sum);
end;
b[n+1]:=-1;
if jj=0 then
writeln('555...')
else
begin
cur:=b[jj];
for i:=jj+1 to n-1 do
if b[i]<>cur then
begin
ii:=i;
break;
end;
cur:=trunc(b[jj]/10000);
writeln(cur,' ',ii-jj);
wbsort(jj,ii-1);
for i:=jj to ii-1 do
writeln(s[i]);
end;
close(input);
close(output);
end. 展开
展开全部
其实"实用向"地告诉你,空间复杂度基本不用自己考虑,只需轻轻点开任务管理器,查看你的程序进程内存情况就行了..
不过话说回来,ansistring和string不同,string是定长字符数组,站位256,但是ansistring是链状结构,开头指针只占4字节,单纯开这些变量不会超出1M.
但是要看你存了什么东西到ansistring里面去,如果每个ansistring都存有10个左右的字符,那么内存就要变成10倍左右了.
不过话说回来,ansistring和string不同,string是定长字符数组,站位256,但是ansistring是链状结构,开头指针只占4字节,单纯开这些变量不会超出1M.
但是要看你存了什么东西到ansistring里面去,如果每个ansistring都存有10个左右的字符,那么内存就要变成10倍左右了.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询