内容目录
哪为朋友帮我看看多关键字排序哪儿错了……
Program P1018; type product=record b,id:longint; p:longint; end; var t,n,i,j,total,count,maxb,mintb,price:longint; visit:array[1..100] of longint; m:array[1..100] of longint; a:array[1..100000] of product; ans:double; function max(a,b:longint):longint; begin if a<b then exit(b) else exit(a); end; function min(a,b:longint):longint; begin if a>b then exit(b) else exit(a); end; procedure qsort(l,r:longint); var i,j:longint; m,p:product; begin i:=l; j:=r; m:=a[(l+r) div 2]; repeat while a[i].b<m.b do inc(i); // while (a[i].p<m.p) and (a[i].b=m.b) do inc(i); // while (a[i].id<m.id) and (a[i].b=m.b) and (a[i].p=m.p) do inc(i); while a[j].b>m.b do dec(j); // while (a[j].p>m.p) and (a[j].b=m.b) do dec(j); // while (a[j].id>m.id) and (a[j].b=m.b) and (a[j].p=m.p) do dec(j); if i<=j then begin p:=a[i]; a[i]:=a[j]; a[j]:=p; inc(i);dec(j); end; until i>j; if l<j then qsort(l,j); if i<r then qsort(i,r); end; begin { assign(input,'p1018.in'); assign(output,'p1018.out'); reset(input); rewrite(output); }read(t); while t>0 do begin total:=0; read(n); mintb:=maxlongint; for i:=1 to n do begin read(m[i]); maxb:=0; for j:=1 to m[i] do begin inc(total); a[total].id:=i; read(a[total].b,a[total].p); maxb:=max(a[total].b,maxb); end; mintb:=min(maxb,mintb); end; qsort(1,total); ans:=0; for i:=1 to total-n+1 do begin if a[i].b>mintb then break; count:=0; fillchar(visit,sizeof(visit),0); visit[a[i].id]:=a[i].p; for j:=i+1 to total do begin if a[j].b<a[i].b then write('x'); if (visit[a[j].id]=0) then begin inc(count); visit[a[j].id]:=a[j].p; end; visit[a[j].id]:=min(visit[a[j].id],a[j].p); end; if count<n-1 then break; price:=0; for j:=1 to n do inc(price,visit[j]); if ans<(a[i].b/price) then ans:=a[i].b/price; end; writeln(ans:3:3); dec(t); end; { close(input); close(output); } end.