CF 1244 C - The Football Season

Posted 1625--h

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF 1244 C - The Football Season相关的知识,希望对你有一定的参考价值。

C - The Football Season

先考虑求解
[ x imes w + y imes d=p ]
若存在一组解
[ egin{cases} x_0y_0 = kw + v & (0<v<w)\end{cases} ]

[ x_0 imes w + y_0 imes d = p\Rightarrow x_0 imes w + (kw+v) imes d = p\Rightarrow x_0 imes w + k imes w imes d + v imes d = p\Rightarrow (x_0+k imes d) imes w + v imes d = p ~~~~~ ]
所以一定存在一组解
[ egin{cases} x = x_0 + k imes dy = v end{cases} ]
并且由于(w> d)


[ x + y = x_0 + k imes d + v < x_0 + k imes w + v ]
前者比后者更有可能成为答案

所以直接枚举所有的v即可

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,p,w,d;
int main(){
    cin >> n >> p >> w >> d;
    for(ll v=0;v<w;v++){
        if((p - v * d) % w == 0){
            ll x = (p - v * d) / w;
            if(x >= 0 && x + v <= n){
                printf("%lld %lld %lld
",x,v,n-x-v);
                return 0;
            }
        }
    }
    puts("-1");
    return 0;
}

以上是关于CF 1244 C - The Football Season的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces 1244C The Football Season (解方程)

CF1244DPaint the Tree(树形DP)

cf 1244 D. Paint the Tree

Codeforces Round #592 (Div. 2) CF1244A Pens and Pencils题解

Codeforces Round #592 (Div. 2) C - The Football Season(推公式)

cf1244C