Imp likes his plush toy a lot.

Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies.
Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies.
The only line contains two integers x and y (0 ≤ x, y ≤ 109) — the number of copies and the number of original toys Imp wants to get (including the initial one).
Print "Yes", if the desired configuration is possible, and "No" otherwise.
You can print each letter in arbitrary case (upper or lower).
6 3
Yes
4 2
No
1000 1001
Yes
In the first example, Imp has to apply the machine twice to original toys and then twice to copies.
题意:
一种玩具复制机器可以:
1.用一个original玩具复制产生另外的一个original玩具和一个copies玩具;
2.用一个copies玩具复制产生另外的两个copies玩具;
没有copies玩具这不能进行第二中复制,初始只有一个original玩具
问:能不能产生x个copies玩具和y个original玩具(包括初始的一个original玩具)
思路:
1.如果y==0,无论x对于几都输出“No”;
2.如果y==1,当x==0时输出“Yes”,当x>0时输出No
3.设第一种复制进行n次,第二种复制进行m次,则
满足 n+1==y && n+m*2=x:
#include<stdio.h>
#include<string.h>
using namespace std;
int main(){
int n,m;
scanf("%d%d",&n,&m);
int x=m-1;
int y=n-x;
if(m==0) printf("No\n");
else if(m==1){
if(n==0) printf("Yes\n");
else printf("No\n");
}
else if(y<0) printf("No\n");
else if(y%2) printf("No\n");
else printf("Yes\n");
return 0;
}
本文介绍了一种玩具复制机器的工作原理及其使用限制。通过数学分析,解决了如何利用该机器达到特定数量的原版和复制玩具的目标。文章给出了具体的实现代码,并通过几个例子展示了算法的有效性。

5619

被折叠的 条评论
为什么被折叠?



