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));
    }
  • 相关阅读:
    n的阶乘
    二叉树遍历
    二分查找练习
    字符串中最长回文序列求解
    复数集合
    AppCrawler自动化遍历使用详解(版本2.1.0 )(转)
    谷歌驱动下载链接
    谷歌浏览器插件
    Pycharm破解方法
    go学习链接
  • 原文地址:https://www.cnblogs.com/superminivan/p/11448257.html
Copyright © 2011-2022 走看看