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

    这个题。。。是一道神奇的贪心题。。。

    根据田忌赛马的原理。。。

    先假使两队都符合田忌和齐王的配置。。。

    我们可以发现如果我们用当前最弱的。。。去和对方当前最强的打。。。

    然后一直按照这个方案。。。当我方最强的能打过对方最强的时候。。。

    在用我方当前最强的。。。和对方当前最强的。。。打。。。

    我们就能得到最多的分数了。。。

    但这里并不完全符合这种配置。。。

    那么我们可以考虑。。。如果我方最弱的。。。能打过对方最弱的。。。

    这种情况是不是该优先考虑呢???

    答案是肯定的。。。这里就不多做证明了。。。大佬们肯定能想出来。。。

    至于最低分。。。反过来就行了。。。

    代码:

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #define maxn 100010
    using namespace std;
    
    int n,own[maxn],foe[maxn];
    
    inline void best()
    {
        int ans=0;
        int head1=1,tail1=n;
        int head2=1,tail2=n;
        while(head1<=tail1)
        {
            if(own[head1]>foe[head2])
            {
                ans+=2;
                head1++,head2++;
            }
            else if(own[tail1]>foe[tail2])
            {
                ans+=2;
                tail1--,tail2--;
            }
            else
            {
                if(own[head1]==foe[tail2])
                    ans++;
                head1++,tail2--;
            }
        }
        printf("%d ",ans);
    }
    
    inline void wost()
    {
        int ans=0;
        int head1=1,tail1=n;
        int head2=1,tail2=n;
        while(head1<=tail1)
        {
            if(own[head1]<foe[head2])
                head1++,head2++;
            else if(own[tail1]<foe[tail2])
                tail1--,tail2--;
            else
            {
                ans+=own[tail1]>foe[head2] ? 2:1;
                tail1--; head2++;
            }
        }
        printf("%d",ans);
    }
    
    int main()
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++) scanf("%d",&own[i]);
        for(int i=1;i<=n;i++) scanf("%d",&foe[i]);
        sort(own+1,own+1+n);
        sort(foe+1,foe+1+n);
        best();
        wost();
    }
    呆码
  • 相关阅读:
    spring和mybatis的结合
    SpringMVC
    springdata
    springboot的总结
    SpringAop代理模式笔记
    springcloud
    完全二叉树和满二叉树
    C# 读取EXCEL文件的三种经典方法
    C#加密app.config中连接字符串的代码
    c#winform 程序 App.config文件加密(SDK命令)
  • 原文地址:https://www.cnblogs.com/zzzyc/p/9030911.html
Copyright © 2011-2022 走看看