POJ 1018(多关键字排序还在wa…)

哪为朋友帮我看看多关键字排序哪儿错了……


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.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值