BZOJ 1034. [ZJOI2008]泡泡堂BNB

 

感觉我双指针不行啊...写了个multiset过的。看了别人代码改了发双指针。

写几个样例大概就知道跟田忌赛马一样了。

#include <bits/stdc++.h>

const int N = 1e5 + 7;
int a[N], b[N];
std::multiset<int> st1, st2;
bool vis[N];

int solve(int A[], int B[], int n) {
    int ans = 0;
    int l1 = 1, l2 = 1, r1 = n, r2 = n;
    while (l1 <= r1 && l2 <= r2) {
        if (A[l1] > B[l2]) ans += 2, l1++, l2++;
        else if (A[r1] > B[r2]) ans += 2, r1--, r2--;
        else ans += (A[l1] == B[r2]) ? 1 : 0, l1++, r2--;
    }
    return ans;
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", a + i);
    for (int i = 1; i <= n; i++)
        scanf("%d", b + i);
    std::sort(a + 1, a + 1 + n);
    std::sort(b + 1, b + 1 + n);
    printf("%d %d\n", solve(a, b, n), 2 * n - solve(b, a, n));
}
View Code

 

posted @ 2020-01-25 14:51  Mrzdtz220  阅读(111)  评论(0编辑  收藏  举报