P2587 [ZJOI2008]泡泡堂

Lisa

贪心,贪心

首先考虑能打就打,我方最牛逼的能干过对方最牛逼的就干他

我们最垃圾的能干过对方最垃圾的就上去干他

如果都不行的话,那就派我方最垃圾的干翻敌方最垃圾的

我方最差情况就是敌方最好情况

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#define lll long long
using namespace std;
int n;
int a[100001];
int b[100001];
int ans;
int main(){
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
	}
	for(int i=1;i<=n;++i){
		cin>>b[i];
	}
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	int l=1,ll=1,r=n,rr=n;
	while(l<=r){
		if(a[l]>b[ll]){
			ans+=2;
			l++;
			ll++;
		}else
			if(a[r]>b[rr]){
				ans+=2;
				r--;
				rr--;
			}
			else {
			if(a[l]==b[rr]){
				ans+=1;
			}
			l++;
			rr--;
		}
	}
	l=1;
	ll=1;
	r=n;
	rr=n;
	cout<<ans<<" ";
	ans=0;
	while(l<=r){
		if(b[l]>a[ll]){
			l++;
			ll++;
		}else
			if(b[r]>a[rr]){
				r--;
				rr--;
			}
			else {
			if(b[l]==a[rr]){
				ans+=1;
			}else{
				ans+=2;
			}
			l++;
			rr--;
		}
	}
	cout<<ans;
	return 0;
}
	

原文地址:https://www.cnblogs.com/For-Miku/p/15359815.html