JZOJ__Day 1:【普及模拟】PLES

来源:互联网 发布:在淘宝怎么搜索精仿鞋 编辑:程序博客网 时间:2024/05/29 05:06

题目描述

   在舞会上有N个男孩和N个女孩,每个人都量过了自己的身高。每个男孩只跟女孩跳舞,并且女孩也只跟男孩跳舞。每个人最

多只有一个舞伴。男孩或者想和比自己高的女孩跳舞,或者想和比自己低的女孩跳舞,同样的,女孩也是或者想和比自己高的男

孩跳舞,或者想和自己低的男孩跳舞。

   你能决定最多有多少对能在一起跳舞么?

输入


第一行是一个正整数N(1<=N<=100000),表示男女的人数。第二行包括N个绝对值在1500到2500的整数,每个整数的绝对值表示每个男孩的身高。如果是一个正整数,表示这个男的喜欢和比他高的女孩跳舞,如果是负整数,就表示这个男的喜欢和比他低的女孩跳舞。第三行包括N个整数,每个整数的绝对值表示相应女孩的身高。同样的,如果是正整数的话,表示这个女孩喜欢和比她高的男孩跳舞,如果是负整数的话,表示这个女孩喜欢和比她低的男孩跳舞。




输出


只有一行一个整数,表示最多的可以搭配的对数。


数据范围限制

提示



程序:

        

varn,i,m,tj,bz,w:longint;a,b:array[0..100000]of longint;procedure kp1(l,r:longint);vari,j,mid:longint;begin    if l>=r then exit;    i:=l;j:=r;mid:=a[(l+r) div 2];    repeat         while a[i]>mid do inc(i);         while a[j]<mid 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;    kp1(l,j);    kp1(i,r);end;procedure kp2(l,r:longint);vari,j,mid:longint;begin    if l>=r then exit;    i:=l;j:=r;mid:=b[(l+r) div 2];    repeat         while b[i]>mid do inc(i);         while b[j]<mid do dec(j);         if i<=j then         begin             b[0]:=b[i];b[i]:=b[j];b[j]:=b[0];             inc(i);dec(j);         end;    until i>j;    kp2(l,j);    kp2(i,r);end;begin    readln(n);    for i:=1 to n do    read(a[i]);    readln;    for i:=1 to n do    read(b[i]);    kp1(1,n);    kp2(1,n);    for i:=1 to n do    if b[i]<0 then    begin        w:=i;        break;    end;    m:=n;tj:=0;    for i:=1 to n do    begin        bz:=0;        if bz=0 then        if a[i]<0 then        if b[m]<0 then        begin            m:=w-1;            bz:=1;        end;        if bz=0 then        if a[i]>0 then        if b[m]<0 then        if abs(b[m])>a[i] then        begin            inc(tj);            dec(m);            bz:=1;        end;        if bz=0 then        if a[i]<0 then        if b[m]>0 then        if b[m]<abs(a[i]) then        begin            inc(tj);            dec(m);            bz:=1;        end;        if m=0 then break;    end;    write(tj);end.

原创粉丝点击