zoukankan      html  css  js  c++  java
  • bzoj1034: [ZJOI2008]泡泡堂BNB

    田忌赛马。

    原理:(假设a队最大得分,得分为res)

    1.如果a最小 > b最小,res += 2。 这样没必要用更大的a来解决这个b。

    else 2.如果a最大 > b最小,res += 2。 这样没必要用更小的a解决这个b,这个b反正都要被解决,如果更小的a能解决这个b,那也能解决别的b。

    else 3.上述两种情况不成立,就用a最小消耗b最大,b最大没人能打过,就用最弱的,a最小打不过别人,就拿它凑数。

    这里要注意一点如果a最小 == b最大,res += 1。(为什么请读者自己体会)

    最坏得分为2*n - b队得分。

    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    const int maxn = 100000 + 10;
    
    int n;
    int a[maxn],b[maxn];
    
    int solve(int a[],int b[]) {
        int l1 = 0,l2 = 0,r1 = n-1,r2 = n-1,res = 0;
        while(l1 <= r1) {
            if(a[l1] > b[l2]) {
                res += 2;
                l1++;
                l2++;
            }
            else if(a[r1] > b[r2]) {
                res += 2;
                r1 --;
                r2 --;
            }
            else {
                res += (a[l1]==b[r2]);
                l1++;
                r2--;
            }
        }
        return res;
    }
    int main() {
        scanf("%d",&n);
        for(int i = 0; i < n; i++) scanf("%d",&a[i]);
        for(int i = 0; i < n; i++) scanf("%d",&b[i]);
        sort(a,a+n);
        sort(b,b+n);
        
        printf("%d %d
    ",solve(a,b),2*n-solve(b,a));
        return 0;
    }

  • 相关阅读:
    MySQL 必知必会学习笔记
    jemter 之cookies管理器
    linux shell通配符、元字符、转义符
    linux cut 、awk、grep、sed
    shell脚本的执行方式
    shell概述
    linux 查看用户常用命令
    linux的挂载命令
    linux关机和重启命令
    linux常用压缩格式
  • 原文地址:https://www.cnblogs.com/invoid/p/5385043.html
Copyright © 2011-2022 走看看