深信服2019春招編程第一題

這是第三套筆試題了 

忙着趕論文的實驗一直沒空更博客emmmm

題意 大概

需要x毫升的飲料

現有500毫升裝 a元

1500毫升裝 b元

求至少花費多少元纔可以滿足至少x毫升

結束了我纔想到可以用完全揹包

仔細看了一下我的解法還是有問題

等題目公開了再更新

#include <iostream>
#include <cstdio>
#include <math.h>
#include<algorithm>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long x,a,b;
        cin>>x>>a>>b;
        long long ans=0;
        double pr1=500.0/a;
        double pr2=1500.0/b;
        if(pr1<pr2)
        {
            ans+=(x/1500)*b;
            x-=(1500*(x/1500));
            //  cout<<x<<endl;
            ans+=(x/500)*a;
            if(x-(500*(x/500))>0)
                ans+=min(a,b);
        }
        else
        {
            ans+=(x/500)*a;
            x-=(500*x/500);
            ans+=(x/1500)*b;
            if(x-(1500*(x/1500))>0)
                ans+=min(a,b);
        }
        cout<<ans<<endl;
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章