【BZOJ 1034】[ZJOI2008]泡泡堂BNB

【题目链接】:http://www.lydsy.com/JudgeOnline/problem.php?id=1034

【题意】

【题解】

如果己方最小的大于对方最小的(严格大于)
或己方最大的大于对方最大的(严格大于)
则让这对最大最小的PK;答案递增2
否则,
采用田忌赛马的思想
用己方最差的马和对方最好的马对碰;
如果相同最好.答案递增1
否则答案递增0(即不变)

【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x)

typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 1e5+100;

int n;
int a[N], b[N],ans1,ans2;

bool cmp1(int a, int b)
{
    return a < b;
}

void in()
{
    rei(n);
    rep1(i, 1, n)
        rei(a[i]);
    rep1(i, 1, n)
        rei(b[i]);
}

void get_ans()
{
    sort(a + 1, a + 1 + n, cmp1), sort(b + 1, b + 1 + n, cmp1);
    int al, ar,bl,br;
    al = 1, ar = n,bl = 1,br = n;
    while (al <= ar && bl <= br)
    {
        if (a[al] > b[bl])
        {
            ans1 += 2;
            al++, bl++;
        }
        else
            if (a[ar] > b[br])
            {
                ans1 += 2;
                ar--, br--;
            }
            else
            {
                if (a[al] == b[br])
                {
                    ans1++;
                }
                al++, br--;
            }
    }
    rep1(i, 1, n)
        swap(a[i], b[i]);
    al = 1, ar = n, bl = 1, br = n;
    while (al <= ar && bl <= br)
    {
        if (a[al] > b[bl])
        {
            al++, bl++;
        }
        else
            if (a[ar] > b[br])
            {
                ar--, br--;
            }
            else
            {
                if (a[al] == b[br])
                {
                    ans2 += 1;
                }
                else
                    ans2 += 2;
                al++, br--;
            }
    }
}

void o()
{
    printf("%d %d\n", ans1, ans2);
}

int main()
{
    //freopen("F:\\rush.txt", "r", stdin);
    in();
    get_ans();
    o();
    //printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
    return 0;
}
posted @ 2017-10-04 18:45  AWCXV  阅读(91)  评论(0编辑  收藏  举报