讨论 / 大牛啊,帮帮我看一下代码哪里错了吧!!! 若有可以改的,那么发我qq。 qq:2637453212 qq邮箱:[email protected]
g++ 2016-03-26 05:20:52
点我顶贴 收藏 删除
var f:array[0..120010] of longint;

i,j,k,l,o,s,t,n:longint;

a:array[0..101] of longint;

h:array[1..120010] of byte;

procedure sort(l,r:longint);

var i,j,v,x:longint;

begin

i:=l; j:=r;

v:=a[(l+r) div 2];

repeat

while a[i]<v do inc(i);

while v<a[j] do dec(j);

if i<=j then begin

x:=a[i]; a[i]:=a[j]; a[j]:=x;

inc(i); dec(j);

end;

until i>j;

if i<r then sort(i,r);

if l<j then sort(l,j);

end;

function dec(n,m:longint):longint;

var i,j,k:longint;

begin

if n>m then i:=n else i:=m;

j:=n+m-i; k:=i;

while i mod j<>0 do i:=i+k;

exit(i);

end;

begin

readln(l);

readln(s,t,n);

fillchar(h,sizeof(h),0);

for i:=1 to n do read(a[i]);

readln;

o:=dec(s,t)*2+100; a[n+1]:=l; a[0]:=0;

sort(1,n);

for i:=1 to n+1 do begin

k:=0;

while a[i]-a[i-1]>o do begin

a[i]:=a[i]-o;

k:=k+o;

end;

for j:=i+1 to n+1 do a[j]:=a[j]-k;

end;

l:=a[n+1];

for i:=1 to n do h[a[i]]:=1;

f[0]:=0;

for i:=1 to l+t do begin

f[i]:=10000000;

for j:=s to t do

if i-j>=0 then

if f[i]>f[i-j]+h[i] then

f[i]:=f[i-j]+h[i];

end;

j:=10000000;

for i:=l to l+t do if f[i]<j then j:=f[i];

writeln(j);

end.

查看更多回复
提交回复