卟之悼 卟之悼
浙江大学~
关注数: 16 粉丝数: 174 发帖数: 3,432 关注贴吧数: 24
存个程序 type node=record x,y:longint; end; var a:array[0..16] of node; dis:array[0..16,0..16] of real; ans1,ans2,v,l,num:array[0..16] of longint; cut:array[0..16] of boolean; n,i,j,minv,t:longint; ans:real; function compare1(p1,p2:node):boolean; begin if p1.y<p2.y then exit(true); if p1.y=p2.y then if p1.x<p2.x then exit(true); exit(false); end; procedure swap(x,y:longint); var t1:node; t2:longint; begin t1:=a[x]; a[x]:=a[y]; a[y]:=t1; t2:=v[x]; v[x]:=v[y]; v[y]:=t2; t2:=l[x]; l[x]:=l[y]; l[y]:=t2; t2:=num[x]; num[x]:=num[y]; num[y]:=t2; end; procedure qsort1(l,r:longint); var i,j,m:longint; begin i:=l; j:=r; m:=(l+r) shr 1; repeat while compare1(a[i],a[m]) do inc(i); while compare1(a[m],a[j]) do dec(j); if i<=j then begin swap(i,j); inc(i); dec(j); end; until i>j; if i<r then qsort1(i,r); if l<j then qsort1(l,j); end; function chaji(p1,p2,p0:node):longint; begin exit((p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x)); end; function compare2(p1,p2:node):boolean; var t:longint; begin t:=chaji(p1,p2,a[1]); if t>0 then exit(true); if t<0 then exit(false); if p1.x<p2.x then exit(true); exit(false); end; procedure qsort2(l,r:longint); var i,j,m:longint; begin i:=l; j:=r; m:=(l+r) shr 1; repeat while compare2(a[i],a[m]) do inc(i); while compare2(a[m],a[j]) do dec(j); if i<=j then begin swap(i,j); if m=i then m:=j else if m=j then m:=i; inc(i); dec(j); end; until i>j; if i<r then qsort2(i,r); if l<j then qsort2(l,j); end; function make:real; var i,tot:longint; bao:array[0..16] of integer; begin tot:=0; fillchar(bao,sizeof(bao),0); for i:=1 to n do if not cut[i] then begin inc(tot); bao[tot]:=i; if tot=2 then break; end; if (tot=0)or(tot=1) then exit(0); for i:=3 to n do if not cut[i] then begin while (tot>1)and(chaji(a[i],a[bao[tot]],a[bao[tot-1]])>=0) do dec(tot); inc(tot); bao[tot]:=i; end; bao[tot+1]:=bao[1]; make:=0; for i:=1 to tot do make:=make+dis[bao[i],bao[i+1]]; end; procedure search(k,vv,le:longint); var ll:real; i:longint; begin if vv>minv then exit; if k>n then begin ll:=make; if (vv<minv)and(le>=ll) then begin ans1:=ans2; minv:=vv; ans:=le-ll; end; exit; end; cut[k]:=true; inc(ans2[0]); ans2[ans2[0]]:=k; search(k+1,vv+v[k],le+l[k]); ans2[ans2[0]]:=0; dec(ans2[0]); cut[k]:=false; search(k+1,vv,le); end; function d(p1,p2:node):real; begin exit(sqrt(sqr(p1.x-p2.x)+sqr(p1.y-p2.y))); end; begin readln(n); for i:=1 to n do readln(a[i].x,a[i].y,v[i],l[i]); for i:=1 to n do num[i]:=i; qsort1(1,n); qsort2(2,n); for i:=1 to n do for j:=1 to n do begin dis[i,j]:=d(a[i],a[j]); dis[j,i]:=dis[i,j]; end; fillchar(cut,sizeof(cut),false); ans:=0; minv:=maxlongint; search(1,0,0); writeln(ans:0:2); for i:=1 to ans1[0]-1 do for j:=i+1 to ans1[0] do if num[ans1[i]]>num[ans1[j]] then begin t:=ans1[i]; ans1[i]:=ans1[j]; ans1[j]:=t; end; for i:=1 to ans1[0] do write(num[ans1[i]],' '); writeln; end.
首页 1 2 3 下一页