zoukankan      html  css  js  c++  java
  • [题解]BZOJ_1034_泡泡堂(贪心

    第一想法是对于我方从大到小二分一个小于它的,但是无法处理平局的情况,因为有可能我方某大数和对面搞个平局之类的,无从下手

    题解的做法是不能无脑送我方小数,因为有可能对位单杀(雾,所以就考虑先看我方最小数能否对位单杀,不能的话再看最大能否单杀,如果都不能再送小数,送的时候还要注意平局的情况

    #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));
    }
  • 相关阅读:
    go install
    web网络安全系统
    Web图片分享系统
    web图库网站
    web视频播放网站
    web商业银行管理平台
    web科技管理信息平台
    web工艺品销售平台
    web房产网站
    感谢!
  • 原文地址:https://www.cnblogs.com/superminivan/p/11448257.html
Copyright © 2011-2022 走看看