Bzoj1034 [ZJOI2008]泡泡堂BNB

来源:互联网 发布:创业软件中签号 编辑:程序博客网 时间:2024/04/27 17:12
原题网址: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
原创粉丝点击