标签:air return printf pre image highlight efi res src
题意简述:给出n,p,w,d,找到满足下面要求的一组解,x,y,z>=0
扩展欧几里得会爆longlong,但是注意观察可以发现,如果有解y<w一定有解,因为d*w可以让x去凑
#include<bits/stdc++.h> #define forn(i, n) for (int i = 0 ; i < int(n) ; i++) #define fore(i, s, t) for (int i = s ; i < (int)t ; i++) #define fi first #define se second #define all(x) x.begin(),x.end() #define pf2(x,y) printf("%d %d\n",x,y) #define pf(x) printf("%d\n",x) #define each(x) for(auto it:x) cout<<it<<endl; #define pii pair<int,int> using namespace std; typedef long long ll; const int maxn=2e6+5; const int maxm=2e5+5; const int inf=1e9; ll n,p,w,d; int main(){ cin>>n>>p>>w>>d; for(ll i=0;i<w;i++){ ll res=p-i*d; if(res>=0 && res%w==0 && i+res/w<=n){ cout<<res/w<<‘ ‘<<i<<‘ ‘<<n-i-res/w<<endl; return 0; } } puts("-1"); }
标签:air return printf pre image highlight efi res src
原文地址:https://www.cnblogs.com/033000-/p/12380353.html