Codeforces Round #592 (Div. 2) C. The Football Season(数学+扩展欧几里得)

题目链接
在这里插入图片描述
在这里插入图片描述
思路:这里就贴一个大佬的题解,感觉讲的非常秒,以后忘了可以再看看。
在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,p,w,d;
int main()
{
	scanf("%lld%lld%lld%lld",&n,&p,&w,&d);
	for(ll i=0;i<=1e5;++i)
	{
		if((p-i*d)%w==0)
		{
			ll x=(p-i*d)/w;
			if(x>=0&&x+i<=n) {printf("%lld %lld %lld\n",x,i,n-x-i);return 0;}
		}
	}
	printf("-1\n");
}
发布了144 篇原创文章 · 获赞 0 · 访问量 4963

猜你喜欢

转载自blog.csdn.net/qq_42479630/article/details/104400546