用户ID: 密码: 验证:

登 录

注 册 取回密码

中山教育

中山国际网

中国教育在线

时代财富科技公司 FortuneAge Technology Co., Ltd. 校园博客客服网站(新)

我的资料

Mpq

博客信息

积分:988
等级:4级 lv 4
日志总数:231
发表评论总数:18 ( 查看)
获得评论总数:21
发表留言总数:0
所属学校:三鑫
收藏本站:

最新公告

欢迎光临我的博客!

最新相册

我的日历

最新评论

--游客
好文好文,是您的手笔?如果是您的文章,如果您愿意和我联系,...
还有就是数学不能使用计算器…….......在读初中之前原...
--Mpq
这次似乎不举行冬季长跑……看来在三鑫参加的体育项目最终是以...
--Mpq
看了你的"总结", 挺有针对性的! 相信下学期你一定会有...

RSS


首页 -> Zoj题库->Island Country
Island Country

Island Country

Time limit: 1 Seconds   Memory limit: 32768K  
Total Submit: 337   Accepted Submit: 72  

Island Country is a very interesting place, in which there are a great many islands. One day Alice and Jim are planning to visit the country. There are so many islands. Which one do they visit at first? Of course all the islands should be visited on. Different islands have different sights, some are interesting and some are boring. The same island is also different for Alice and Jim. One island interesting for Alice may be boring for Jim. They both decide to visit at the islands from the least interesting one (also the most boring one) he or she regards. And then the second least ... at last the most interesting one. Because of their different viewpoints, they cannot enjoy their journey together. The time they visit at each island is arbitrary (you deicde (: ). If they have visited at an island at the same time, they could meet the other. Now your job is to decide the maximal times they could meet.

You will be given the information of all the islands (assuming N islands numbered from 1 to n): two integer sequences a[1], a[2], ..., a[n] and b[1], b[2], ..., b[n], where a[i] denotes how Alice thinks about the ith island (the larger the more interesting) and b[i] denotes how Jim thinks about it.

For instance n = 3, a[1] = 1, a[2] = 2, a[3] = 3, b[1] = 3, b[2] = 1, b[3] = 2, Alice thinks the first island is the most boring one, so she will visit there first and then the second one and the third one at last. For Jim, he will first visit the second island and then the third and at last the first one.

Input

The first line stands an integer N (0 < N <= 1000), and the second line stands N integers which denote Alice's viewpoints on all the islands. The next line also stands N integers denoting Jim's viewpoints. It's the end when you meet N = 0.


Output

Just one integer on a single line for each case, indicating the maximal times they could meet.

Sample Input

3
1 2 3
3 1 2
0

Sample Output

2

Note: if two islands have the same value on interests, he or she will always visit the former one in numbers.

 

程序:

Program Zoj_2254_Mpq;
{$inline on}

type data=array[0..1000,1..2] of longint;
var
  a,b:data;
  f,c,u:array[1..1000] of integer;
  n:longint;

procedure qsort(l,r:integer; var a:data); inline;
var
  i,j:integer;
  m,m1:longint;
begin
  i:=l; j:=r; m:=a[(i+j) div 2,1]; m1:=a[(i+j) div 2,2];
  repeat
    while (a[i,1]<m)or((a[i,1]=m)and(a[i,2]<m1)) do inc(i);
    while (a[j,1]>m)or((a[j,1]=m)and(a[j,2]>m1)) do dec(j);
    if i<=j then
    begin
      a[0]:=a[i];
      a[i]:=a[j];
      a[j]:=a[0];
      inc(i);
      dec(j);
    end;
  until i>j;
  if l<j then qsort(l,j,a);
  if i<r then qsort(i,r,a);
end;

procedure init;
var
  i:integer;
begin
  for i:=1 to n do
  begin
    read(a[i,1]);
    a[i,2]:=i;
  end;
  readln;
  for i:=1 to n do
  begin
    read(b[i,1]);
    b[i,2]:=i;
  end;
  qsort(1,n,a);
  qsort(1,n,b);
  for i:=1 to n do u[b[i,2]]:=i;
  for i:=1 to n do c[i]:=u[a[i,2]];
end;

procedure Dp;
var
  i,m,Min,Max,Len:longint;
begin
  Len:=1; f[1]:=c[1];
  for i:=2 to n do
  begin
    Min:=1; Max:=Len;
    while Min<=Max do
    begin
      m:=(Min+Max) div 2;
      if f[m]<c[i] then Min:=M+1 else
                        Max:=M-1;
    end;
    f[Min]:=c[i];
    if Min>Len then Len:=Min;
  end;
  writeln(Len);
end;

begin
  readln(n);
  while n<>0 do
  begin
    init;
    Dp;
    readln(n);
  end;
end.

网友评论

共 0 页,0 条记录  

用户名:
密码:
您的评论:
正在载入编辑器...
请输入验证码:


发 表 评 论

Mpq-中山教师家园