A. Cloning Toys
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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.
Input
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).
Output
Print “Yes”, if the desired configuration is possible, and “No” otherwise.
You can print each letter in arbitrary case (upper or lower).
Examples
inputCopy
6 3
output
Yes
inputCopy
4 2
output
No
inputCopy
1000 1001
output
Yes
Note
In the first example, Imp has to apply the machine twice to original toys and then twice to copies.
题意:
给你a和b两个数分别代表x和y的种类的个数,有2种生产方式,一种是用一个y生产2个y和一个x,一种是用一个x生产3个x,一开始有1个y,问给出的a,b是否能够实现。
思路:
首先若要生产y,只有方法2,所以我们能先算出以第二种的方式来生产的x有多少,再用a减去该方式生产出来的x,剩余的x只能由方式1生产,此时再判断就行。
code:
#include<stdio.h>
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
int main()
{
long long a,b,c;
while(cin>>a>>b)
{
c=a-b+1;
if(c<0||(b>1&&a==0)||b==0||(b==1&&a>0))
cout<<"No"<<endl;
else
{
if(c%2==0)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
}
return 0;
}