http://acm.timus.ru/problem.aspx?space=1&num=1430
先让 a 变成较大的那个
1,a 的个数 不会超过 n/a
2,a 的个数也可以不超过 b ,如果超过 b个a 可以由 a个b 代替 从而减轻了 a 的个数过大的负担
然后枚举 a 的个数
因为 a 变成较大的那个 所以 min(n/a,b) 比较小
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#define LL long long
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int INF=0x3f3f3f3f;
int main()
{
    //freopen("data.txt","r",stdin);
    LL a,b,n;
    while(cin>>a>>b>>n)
    {
        bool change=false;
        if(a<b)
        {change=true;swap(a,b);}
        LL k1,k2,MAX=-1;
        for(LL i=0;i<=min(n/a,b);++i)
        {
            LL j=(n-i*a)/b;
            if(i*a+j*b>MAX)
            {
                MAX=i*a+j*b;
                k1=i;
                k2=j;
            }
        }
        if(change)
        swap(k1,k2);
        cout<<k1<<" "<<k2<<endl;
    }
    return 0;
}
 
                    
                 
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号