首页 > 其他 > 详细

cf1244C

时间:2020-02-28 22:48:48      阅读:76      评论:0      收藏:0      [点我收藏+]

题意简述:给出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");
	
}

  

 

cf1244C

原文:https://www.cnblogs.com/033000-/p/12380353.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!