BZOJ 1034: [ZJOI2008]泡泡堂BNB

二次联通门 : BZOJ 1034: [ZJOI2008]泡泡堂BNB

 

 

 

 

 

/*
    BZOJ 1034: [ZJOI2008]泡泡堂BNB

    贪心
    如果最强能打过对方的最强,就打    
    否则就用最弱的去打最强的

    最差策略就是把对手变成自己,自己变成对手
*/
#include <cstdio>
#include <iostream>
#define rg register
#include <algorithm>

inline void read (int &n)
{
    rg char c = getchar ();
    for (n = 0; !isdigit (c); c = getchar ());
    for (; isdigit (c); n = n * 10 + c - '0', c = getchar ());
}

#define Max 200006
int N;
int Calc (int *a, int *b)
{
    rg int l1 = 1, l2 = 1, r1 = N, r2 = N;
    int res = 0;
    for (; l1 <= r1 && l2 <= r2; )
    {
        if (a[l1] > b[l2]) ++ l1, ++ l2, ++++ res;
        else if (a[r1] > b[r2]) ++++ res, -- r1, -- r2;
        else res += (a[l1] == b[r2]), ++ l1, -- r2;
    }    
    return res;
}
int a[Max], b[Max];

int main (int argc, char *argv[])
{
    read (N); rg int i;
    for (i = 1; i <= N; ++ i) read (a[i]);

    for (i = 1; i <= N; ++ i) read (b[i]);
    
    std :: sort (a + 1, a + 1 + N);    
    std :: sort (b + 1, b + 1 + N);

    printf ("%d %d", Calc (a, b), 2 * N - Calc (b, a));

    return 0;
}

 

posted @ 2017-12-28 16:47  ZlycerQan  阅读(199)  评论(0编辑  收藏  举报