zoukankan      html  css  js  c++  java
  • luogu P1080国王游戏

    贪心加高精

    传送门:QWQ

    先考虑两个人

    a0 b0
    p1 a1 b1
    p2 a2 b2

    那么满足:(huge ans1=max(frac{a0}{b1} , frac{a0a1}{b2}))

    a0 b0
    p2 a2 b2
    p2 a1 b1

    (huge ans2=max(frac{a0}{b2} , frac{a0a2}{b1}))

    如果要让ans1<ans2

    (k1=frac{a0}{b1} , k2=frac{a0a1}{b2} , k3=frac{a0}{b2} , k4=frac{a0a2}{b1})

    则 k1< k4

    k2 > k3

    如果要让ans1<ans2

    那么 k4 > k2

    展开,得:(frac{a0a2}{b1} > frac{a0a1}{b2})

    移项得:(a1b1<a2b2)

    根据冒泡排序

    两个相邻交换一定使答案更差

    所以可以根据ab的大小排序(下标排序)

    然后就是麻烦的高精了

    //自动无视c++14
    // luogu-judger-enable-o2
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    const int maxn=1e4+5;
    int n;
    // The MIT License (MIT)
    
    // Copyright (c) YEAR NAME
    
    //  Permission is hereby granted, free of charge, to any person obtaining a
    //  copy of this software and associated documentation files (the "Software"),
    //  to deal in the Software without restriction, including without limitation
    //  the rights to use, copy, modify, merge, publish, distribute, sublicense,
    //  and/or sell copies of the Software, and to permit persons to whom the
    //  Software is furnished to do so, subject to the following conditions:
    //
    //  The above copyright notice and this permission notice shall be included in
    //  all copies or substantial portions of the Software.
    //
    //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    //  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    //  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    //  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    //  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    //  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    //  DEALINGS IN THE SOFTWARE.
    struct big{
        static const int base=10000;
        int a[2333];
        int len;
        big(){memset(a,'00',sizeof a);len=1;}
        int& operator[](int x){return a[x];}
        big(int x){*this=x;}
        big& operator =(int x){
            *this=big();
            for(len=0;x;x/=base)a[++len]=x%base;
            if(!x)len=1;
            return *this;
        } 
        friend big operator + (const big&a,const big& b){
            big c;
            c.len=max(a.len,b.len);
            for(int i=1;i<=c.len;++i){
                c[i+1]+=((c[i]+=(a.a[i]+b.a[i]))/base);
                c[i]%=base;
            }
            if(c[c.len+1])c.len++;
            return c;
        }
        friend big operator * (const big&a,const big& b){
            big c;
            c.len=a.len+b.len-1;
            for(int i=1;i<=a.len;++i){
                for(int j=1;j<=b.len;++j){
                    c[i+j-1]+=a.a[i]*b.a[j];
                    c[i+j]+=c[i+j-1]/base;
                    c[i+j-1]%=base;
                }
            }
            while(c[c.len+1]){
                c[c.len+1]+=c[c.len]/base;
                c[c.len]%=base;
                c.len++;
            }
            return c;
        }
        friend big operator + (const big a,int b){big c(b);return a+c;}
        friend big operator * (const big a,int b){big c(b);return a*c;}
        friend bool operator < (const big & a,const big&b){
            if(a.len==b.len){
                for(int i=a.len;i;--i){
                    if(a.a[i]!=b.a[i])return a.a[i]<b.a[i];
                }
            }else{
                return a.len<b.len;
            }
            return 0;
        }
        friend big operator / (const big& a,int x){
            big ans;
            ans.len=a.len;
            int jw=0;
            for(int i=ans.len;i;--i){
                ans[i]=(jw*base+a.a[i])/x;
                ((jw*=base)+=a.a[i])%=x;
            }
            while(!ans[ans.len]&&ans.len)ans.len--;
            return ans;
        }
        void print()const{printf("%d",a[len]);
            for(int i=len-1;i;i--){
                printf("%04d",a[i]);
            }
        }
        friend ostream& operator << (ostream& out,const big& a){
            a.print();
            return out;
        }
    };
    int a[maxn],b[maxn];
    int bit[maxn];
    big f[maxn];
    big ans;
    big mul(1);
    int main(){
        cin>>n;
        for(int i=0;i<=n;++i){
            cin>>a[i]>>b[i];
            big x(a[i]),y(b[i]);
            f[i]=x*y;
            bit[i]=i;
        }
        sort(bit+1,bit+1+n,[](const int& a,const int& b){
            return f[a]<f[b];
        });
        for(int i=0;i<=n;++i){
            if(i)ans=max(ans,mul/b[bit[i]]);
            mul=mul*a[bit[i]];
        }
        ans.print();
        return 0;
    }
    
  • 相关阅读:
    Vue 获取dom元素中的自定义属性值
    php文件包含
    php数组运算符
    管理一组事物的状态
    php数据类型转换
    php函数
    PHP循环while do while循环
    php的流程控制 if elseif swich case for循环
    php的工作原理
    python算数、逻辑运算,位运算
  • 原文地址:https://www.cnblogs.com/eric-walker/p/9535445.html
Copyright © 2011-2022 走看看