From 84f89b8b93b967fabe2680fa42cfb551ccb8c160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E5=AE=87=E8=BE=B0?= Date: Tue, 6 Dec 2016 21:46:53 +0800 Subject: [PATCH] bzoj 1034 --- OnlineJudges/lydsy/1034.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 OnlineJudges/lydsy/1034.cpp diff --git a/OnlineJudges/lydsy/1034.cpp b/OnlineJudges/lydsy/1034.cpp new file mode 100644 index 0000000..87c1de3 --- /dev/null +++ b/OnlineJudges/lydsy/1034.cpp @@ -0,0 +1,33 @@ +#include +#include +#include +using namespace std; +inline void readInt(int &x) +{ + int ch = x = 0; + while (!isdigit(ch = getchar())); + for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; +} +int n, zj[100001], jr[100001]; +int calc(int *A, int *B) +{ + int ret = 0; + int la = 0, lb = 0, ra = n - 1, rb = n - 1; + while (la <= ra) + if (A[ra] < B[lb]) break; + else if (A[la] > B[lb]) la++, lb++, ret += 2; + else if (A[ra] > B[rb]) ra--, rb--, ret += 2; + else + if (A[la++] == B[rb--]) ret++; + return ret; +} +int main() +{ + readInt(n); + for (int i = 0; i < n; i++) readInt(zj[i]); + for (int i = 0; i < n; i++) readInt(jr[i]); + sort(zj, zj + n); + sort(jr, jr + n); + printf("%d %d", calc(zj, jr), (n << 1) - calc(jr, zj)); + return 0; +} \ No newline at end of file