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.
这题是找规律的题,不过有坑点,需要考虑y=1,x只能=0,以及y=0的情况不存在
代码如下:
#include<stdio.h>
int main()
{
int x,y;
while(~scanf("%d %d",&x,&y))
{
if(y==1&&x>0||y==0)
printf("No
");
else
{
int t=y-1;
if((x-t)%2==0&&x-t>=0)
{
printf("Yes
");
}
else
printf("No
");
}
}
return 0;
}
刚开始读题,就凭借自己的主观印象觉得x,y是谁,结果分析样例怎么都分析不对.......
以后读题一定要仔细看每一个变量分别代表的是谁......
最开始想的这个规律有一点漏洞,那就是没考虑到对于每一个y,x都有一个最小值,如果数据比这个值小的话,也是不行的(刚才手滑,不小心把键盘弄掉了,现在回来继续.....)
推规律的时候耐心一点,不然交上去也是wa