讨论 / 参考解法
disino 2008-09-17 17:03:00
点我顶贴 收藏 删除
type pnt=^node;

node=record

data:longint;

pre,next:pnt;

end;

var flag:array [1..5000000] of boolean;

a:array [1..30000] of longint;

i,j,temp,n,m,mm:longint;

t,s:ansistring;

head,p:pnt;

flags:boolean;

procedure solve(var k:pnt;kk:integer);

var i,j:longint;

begin

flags:=true;

if mm=0 then exit;

if k^.pre^.data<k^.data then

begin

if k^.pre^.pre=nil then

begin

k^.pre:=nil;head:=k;

end

else

begin

k^.pre^.pre^.next:=k;k^.pre:=k^.pre^.pre;flags:=false;

end;

dec(mm);

end;

end;

begin

readln(n,m);

a[1]:=1;flag[1]:=true;j:=1;

for i:=3 to 5000000 do

if (i>5) and ((i-5) mod 4=0) and flag[(i-5) div 4] then

begin

inc(j);a[j]:=i;flag[i]:=true;if j=n then break;

end

else

if ((i-1) mod 2=0) and flag[(i-1) div 2] then

begin

inc(j);a[j]:=i;flag[i]:=true;if j=n then break;

end;

new(p);p^.pre:=nil;head:=p;s:=’’;

for i:=1 to n do

begin

str(a[i],t);

s:=s+t;

for j:=1 to length(t) do

begin

val(t[j],temp);p^.data:=temp;

if (i<n) or (j<length(t)) then

begin

new(p^.next);

p^.next^.pre:=p;

p:=p^.next;

end

else if (i=n) and (j=length(t)) then p^.next:=nil;

end;

end;

writeln(s);

p:=head^.next;mm:=m;

while not (p=nil) do

begin

solve(p,1);

if flags then p:=p^.next;

end;

p:=head;

for i:=1 to length(s)-m do

begin

write(p^.data);

p:=p^.next;

end;

end.

#1 Steven06@2018-10-20 15:02:18
回复 删除
什么意思?
查看更多回复
提交回复