sgu141:Jumping Joe

141. Jumping Joe

time limit per test: 0.25 sec. 
memory limit per test: 4096 KB

Joe is a frog who likes to jump a lot. In fact, that's all he does: he jumps forwards and backwards on the integer axis (a straight line on which all the integer numbers, both positive and negative are marked). At first, Joe sits next to the point marked with 0. From here, he can jump in the positive or the negative direction a distance equal to either x1 or x2. From the point where he arrived, he can jump again a distance equal to x1 or x2, in the positive or the negative direction and so on.. Joe wants to arrive next to the point marked with the number P, after exactly K jumps. You have to decide whether such a thing is possible.

Input

The input will contain four integers: x1x2 (0 < x1 , x2 < 40 000), P (-40 000 < P  < 40 000) and (0 <= K < 2 000 000 000), separated by blanks.

Output

The first line of output will contain the word "YES", in case Joe can reach the point marked with P after exactly K jumps, or "NO", otherwise. In case the answer is "YES", the next line should contain four integers, separated by blanks: P1 N1 P2 and N2P1 is the number of times Joe jumped in the positive direction a distance equal to x1N1 is the number of times Joe jumped in the negative direction a distance equal to x1P2 is the number of times Joe jumped in the positive direction a distance equal to x2N2 is the number of times Joe jumped in the negative direction a distance equal to x2. In other words, you should find four non-negative integers, so that:

P1*x1 - N1*x1 + P2*x2 - N2*x2 = P 
P1 + N1 + P2 + N2 = K

In case there are more quadruples (P1,N1,P2,N2) which are solutions for the problem, you may print any of them.

Sample Input

2 3 -1 12

Sample Output

YES
1 0 5 6

Author: Mugurel Ionut Andreica
Resource: SSU::Online Contester Fall Contest #2
Date: Fall 2002
设x=p1-n1,y=p2-n2,则有x*x1+y*x2=p(①),如果p%GCD(x1,x2)!=0很明显无解;
通过扩展GCD求出x,y的一个特解,然而这并不一定是最终的答案,很明显由于p1,n1,p2,n2为非负整数,有|x|+|y|<=k;(可以自己尝试着严格证明)
方程①的通解为x'=x+t*x2/gcd(x1,x2),y'=y-t*x1/gcd(x1,x2),我们可以通过这种方法来对x,y缩放得到最小的|x|+|y|。
(1)如果|x|+|y|>k显然无解。否则到(2)。
(2)我们可以把求出的x,y先赋给p1,n1,p2,n2,还剩下rest=k-|x|-|y|。
(3)如果rest为偶数,p1+=rest/2,n1+=rest/2即可;若rest为奇数,通过之前的方法来调整x和y的值,但如果x2/gcd(x1,x2)+x1/gcd(x1,x2)为偶数的话,无论怎么改变t的值,rest均为奇数,此时无解;
如果x2/gcd(x1,x2)+x1/gcd(x1,x2)为奇数,把t++或t--即可,转到(1)。

详见代码:

#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std; 

int ext(int a, int b, int &x, int &y)
{
	while(!b)
	{
		x = 1;
		y = 0;
		return a;	
	}
	int re = ext(b, a%b, x, y);
	int tmp = x;
	x = y;
	y = tmp-a/b*y;
	return re;
}

int main()
{
	int x1 = 0, x2 = 0, p = 0, k = 0;
	int x, y, gcd, _x, _y;
	int p1, n1, p2, n2;
	scanf("%d%d%d%d", &x1, &x2, &p, &k);
	gcd = ext(x1, x2, x, y);
	if(p%gcd != 0)
	{
		puts("NO");
		return 0; 
	}
	
	x *= p/gcd;
	y *= p/gcd;
	_x = x2/gcd;
	_y = x1/gcd;
	
	while(abs(x+_x)+abs(y-_y) < abs(x)+abs(y)) 
	{
		x += _x;
		y -= _y;
	}
	while(abs(x-_x)+abs(y+_y) < abs(x)+abs(y)) 
	{
		x -= _x;
		y += _y;	
	}
	
	if(abs(x)+abs(y) > k)
	{
		puts("NO");
		return 0;	
    }
	if(!((k-abs(x)-abs(y))&1))
	{
	  	int tmp = (k-abs(x)-abs(y))>>1;
	 	if(x < 0) p1 = 0, n1 = -x;
	  	else p1 = x, n1 = 0;
	  	if(y < 0) p2 = 0, n2 = -y;
	  	else p2 = y, n2 = 0;
	  	p1 += tmp;
	  	n1 += tmp; 	
	}
	else 
	{
		if((_x+_y)&1)
		{
			if(abs(x+_x)+abs(y-_y) <= k) 
			{
				x += _x;
				y -= _y;	
			}
			else if(abs(x-_x)+abs(y+_y) <= k)
			{
				x -= _x;
				y += _y;	
			}
			else 
			{
			  	puts("NO");
				return 0;
			}
			int tmp = (k-abs(x)-abs(y))>>1;
	 		if(x < 0) p1 = 0, n1 = -x;
	  		else p1 = x, n1 = 0;
	  		if(y < 0) p2 = 0, n2 = -y;
	  		else p2 = y, n2 = 0;
	  		p1 += tmp;
	  		n1 += tmp; 	
	    }
	    else 
	    {
	    	puts("NO");
			return 0;
	    }
	}
	puts("YES");
	printf("%d %d %d %d\n", p1, n1, p2, n2);
	return 0;  	
}


内容概要:本文详细探讨了智慧医疗建设的历程、现状、挑战及未来发展趋势。智慧医疗建设经历了信息化、数字化和数智化三个阶段,政策、需求和技术是其发展的三大推动力。文章指出,当前智慧医疗已从数据收集与治理阶段迈向数据价值应用阶段,特别是在高质量数据库建设、云计算、人工智能等技术的推动下,实现了临床科研、药物研发、真实世界研究及数字营销等多个场景的商业化落地。此外,文中还分析了医疗信息化系统同质化、数据孤岛、互联互通等痛点,并提出了云化转型、新产品、新技术和新服务作为突破方向。最后,通过奈特瑞、医渡科技、东软集团三个企业案例,展示了不同企业在智慧医疗领域的创新实践。 适合人群:医疗信息化从业者、医疗行业研究人员、医疗机构管理者、医疗科技企业相关人员、政策制定者及对智慧医疗感兴趣的投资者。 使用场景及目标:①了解智慧医疗建设的阶段性特征和发展趋势;②掌握医疗信息化建设中的关键技术和应用场景;③探讨解决医疗信息化系统同质化、数据孤岛等问题的策略;④学习企业如何通过新产品、新技术和新服务实现突破,推动智慧医疗发展。 其他说明:本文通过对智慧医疗建设的深入剖析,强调了政策导向、技术创新和市场需求的重要性,为企业和政策制定者提供了宝贵的参考。同时,文章也揭示了未来智慧医疗发展的广阔前景,特别是在数据资产化和数智化应用方面的巨大潜力。阅读时应注意结合政策背景和技术发展趋势,关注行业动态和企业创新实践。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值