Bzoj1034 [ZJOI2008]泡泡堂BNB

原题网址:http://www.lydsy.com/JudgeOnline/problem.php?id=1034
推荐vfleaking的贪心:http://vfleaking.blog.163.com/blog/static/174807634201302175150796/
var
  a,b,c,temp:array[0..100050] of longint;
  used:array[0..100050] of boolean;
  n,i:longint;
procedure sort(l,r:longint);
  var
    i,j,e,t:longint;
  begin
    i:=l;j:=r;e:=c[(l+r)>>1];
    repeat
      while c[i]<e do inc(i);
      while e<c[j] do dec(j);
      if not (i>j) then
        begin
          t:=c[i];c[i]:=c[j];c[j]:=t;
          inc(i);dec(j);
        end;
    until i>j;
    if l<j then sort(l,j);
    if i<r then sort(i,r);
  end;
function solve:longint;
  var
    p,i,cnt,ans:longint;
  begin
    fillchar(used,sizeof(used),false);
    ans:=0;p:=1;cnt:=0;
    for i:=1 to n do
      begin
        while ((p<=n)and(a[i]>b[p])) do
          begin
            inc(cnt);
            temp[cnt]:=b[p];
            inc(p);
          end;
        if (cnt>0) then
          begin
            inc(ans,2);
            dec(cnt);
            used[i]:=true;
          end;  
      end;
    for i:=p to n do begin inc(cnt);temp[cnt]:=b[i]; end;
    p:=1;
    for i:=1 to n do
      if (not used[i])and (a[i]=temp[p])
            then begin inc(ans);inc(p);end;
    exit(ans);
  end;
begin
  read(n);
  for i:=1 to n do read(c[i]);
  sort(1,n);a:=c;
  for i:=1 to n do read(c[i]);
  sort(1,n);b:=c;
  write(solve,' ');
  c:=a;a:=b;b:=c;
  writeln(n*2-solve);
end.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值