[Explanations] BZOJ_1034_ BNB (greedy

For our first thought was descending a half less than it is, but can not handle the event of a tie, because a large number and we put forward a draw is likely across and the like, can not start

Practice solution to a problem is not no brain decimal send us, because it is possible to place a single kill (fog, so we look to consider whether the minimum number of bits single kill, can not, then look at whether the largest single kill, if all the situation can not be sending decimals, send time also pay attention to a draw

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=100009;
int n,a[maxn],b[maxn];
int work(int a[],int b[]){int ans=0;
    int h1=1,h2=1,t1=n,t2=n;
    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(){
    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]);
    sort(a+1,a+1+n);
    sort(b+1,b+1+n);
    printf("%d %d",work(a,b),2*n-work(b,a));
}

 

Guess you like

Origin www.cnblogs.com/superminivan/p/11448257.html