Codeforces Round #451 (Div. 2) B

 我一开始,同时暴力枚举2种东西的的数量,结果T了,后来看题解才知道要有技巧的暴力,就枚举第一种物品的数量就好了,然后判断一下剩余的钱能不能全部用来买第二种物品即可

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,maxc,maxb;
    cin>>n>>a>>b;
    maxc=n/a;
    for(int i=0;i<=maxc;i++)
    {
        int tmp=n-i*a;
        if(tmp%b==0)
        {
            cout<<"YES"<<endl;
            cout<<i<<" "<<tmp/b<<endl;
            return 0;
        }

    }
    cout<<"NO"<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_40642465/article/details/81333960