D. Zookeeper and The Infinite Zoo
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
There is a new attraction in Singapore Zoo: The Infinite Zoo.
The Infinite Zoo can be represented by a graph with an infinite number of vertices labeled 1,2,3,…1,2,3,…. There is a directed edge from vertex uu to vertex u+vu+v if and only if u&v=vu&v=v, where && denotes the bitwise AND operation. There are no other edges in the graph.
Zookeeper has qq queries. In the ii-th query she will ask you if she can travel from vertex uiui to vertex vivi by going through directed edges.
Input
The first line contains an integer qq (1≤q≤1051≤q≤105) — the number of queries.
The ii-th of the next qq lines will contain two integers uiui, vivi (1≤ui,vi<2301≤ui,vi<230) — a query made by Zookeeper.
Output
For the ii-th of the qq queries, output "YES" in a single line if Zookeeper can travel from vertex uiui to vertex vivi. Otherwise, output "NO".
You can print your answer in any case. For example, if the answer is "YES", then the output "Yes" or "yeS" will also be considered as correct answer.
Example
input
Copy
5 1 4 3 6 1 6 6 2 5 5
output
Copy
YES YES NO NO YES
Note
The subgraph on vertices 1,2,3,4,5,61,2,3,4,5,6 is shown below.
=========================================================================
最反感这种caodan的打表题,打表可以发现,我们每次加的是本数字有的,加完之后是一个进位操作,也就是一个数可以衍生出来无数个数字,这些数字的二进制为1的数位一定少于等于原数,且都是进位或者保留得来的,那么只需要看原数与要转化的数字二进制位即可
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
int t;
cin>>t;
while(t--)
{
int x,y;
cin>>x>>y;
if(x>y)
{
cout<<"NO"<<endl;
}
else if(x==y)
{
cout<<"YES"<<endl;
}
else
{
int cnt1=0,cnt2=0,flag=0;
for(int i=0;i<=30;i++)
{
if((x&(1ll<<i)))
cnt1++;
if((y&(1ll<<i)))
cnt2++;
if((y&(1<<i)))//需要有个进位
{
if(cnt1==0)
{
flag=1;
break;
}
cnt1--;
}
}
if(flag)
{
cout<<"No"<<endl;
}
else
{
cout<<"YES"<<endl;
}
}
}
return 0;
}