【BZOJ1034】[ZJOI2008]泡泡堂BNB【贪心】【田忌赛马】

田忌赛马贪心...


/* Footprints In The Blood Soaked Snow */
#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn = 100005;

int n, A[maxn], B[maxn];

inline int iread() {
	int f = 1, x = 0; char ch = getchar();
	for(; ch < '0' || ch > '9'; ch = getchar()) f = ch == '-' ? -1 : 1;
	for(; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	return f * x;
}

inline int solve(int a[], int b[]) {
	int h1 = 1, t1 = n, h2 = 1, t2 = n, ans = 0;
	while(h1 <= t1 && h2 <= t2) {
		if(a[h1] > b[h2]) ans += 2, h1++, h2++;
		else if(a[t1] > b[t2]) ans +=2, t1--, t2--;
		else ans += (a[h1] == b[t2]), h1++, t2--;
	}
	return ans;
}

int main() {
	n = iread();
	for(int i = 1; i <= n; i++) A[i] = iread();
	for(int i = 1; i <= n; i++) B[i] = iread();
	
	sort(A + 1, A + 1 + n); sort(B + 1, B + 1 + n);	
	printf("%d %d\n", solve(A, B), (n << 1) - solve(B, A));
	return 0;
}


你可能感兴趣的:(贪心,田忌赛马)