2 条题解

  • 0
    @ 2025-3-15 10:55:30
    #include<bits/stdc++.h>
    typedef long long ll;
    
    using namespace std;
    const int N=1010;
    struct Node{
        int l,r;
    }node[N];
    
    bool cmp(Node a,Node b){
        return a.l*a.r<b.l*b.r;
    }
    
    vector<int> mul(vector<int>a,int b){//高精度乘法
        vector<int>c;
        int t=0;
        for(int i=0;i<a.size();i++){
            t+=a[i]*b;
            c.push_back(t%10);
            t/=10;
        }
        while(t){
            c.push_back(t%10);
            t/=10;
        }
        return c;
    }
    
    
    vector<int>div(vector<int>a,int b){//高精度除法
        vector<int> c;
        bool flag=true;
        int t=0;
        for(int i=a.size()-1;i>=0;i--){
            t=t*10+a[i];
            int x=t/b;
            if(!flag||x){
                flag=false;
                c.push_back(x);
            }
            t%=b;
        }
        reverse(c.begin(),c.end());
        return c;
    }
    
    
    vector<int>max_vec(vector<int>a,vector<int>b){
        if(a.size()>b.size()) return a;
        if(a.size()<b.size()) return b;//从最高位比较
        if(vector<int>(a.rbegin(),a.rend())>vector<int>(b.rbegin(),b.rend()))
            return a;
        else
            return b;
    }
    
    int main(void){
        int n;
        cin>>n;
        for(int i=0;i<=n;i++)
            cin>>node[i].l>>node[i].r;
        sort(node+1,node+n+1,cmp);
        vector<int>a(1,1);
        vector<int>res(1,0);
        for(int i=0;i<=n;i++){
            if(i) res=max_vec(res,div(a,node[i].r));
            a=mul(a,node[i].l);
        }
        for(int i=res.size()-1;i>=0;i--)
            cout<<res[i];
        cout<<endl;
        return 0;
    }
    

    高精度写法

    • 0
      @ 2025-3-15 10:35:09

      过一半

      #include <bits/stdc++.h>
      
      using namespace std;
      
      struct Minister{
        int a,b;
        bool operator<(const Minister& other)const{
          return a*b < other.a*other.b;
        }
      };
      
      int main()
      {
        int n;
        cin>>n;
        vector<Minister>ministers(n+1);
        for(int i = 0;i<=n;++i)
        {
          cin>>ministers[i].a>>ministers[i].b;
        }
        sort(ministers.begin()+1,ministers.end());
        long long product = ministers[0].a;
        long long  max_coins = 0;
        for(int i = 1;i<=n;i++)
        {
          max_coins = max(max_coins,product/ministers[i].b);
          product *= ministers[i].a;
        }
        cout << max_coins<<endl;
      
        return 0;
      }
      
      • 1

      信息

      ID
      5138
      时间
      1000ms
      内存
      125MiB
      难度
      4
      标签
      递交数
      55
      已通过
      16
      上传者